PHP code example of ericsnguyen / micromongo

1. Go to this page and download the library: Download ericsnguyen/micromongo library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ericsnguyen / micromongo example snippets


    list($mongo, $database) = ApplicationDbContext::initialDbConnection();
    // binding it to DI container to reuse
    SimpleDi::bindingInstance(Database::class,$database);
    SimpleDi::bindingInstance(Client::class, $mongo);

class ARandomEntity extends BaseEntity
{
    /**
     * if you want to igrnore this field,
     * just put @\MicroOdm\Annotations\UnPersist() to it
     * @UnPersist
     * @var array
     */
    private array $domainEvents = [];    
    protected ?int $iid;
    // for multi domain
    protected ?string $dmn;
    protected ?string $school;
    protected ?User $u;
    
    // for the nest object, must define full namespace
    // we will upgrade in next version
    /**
     * @return \Uni\Domains\Share\ObjectValues\User|null
     */
    public function getU(): ?User
    {
        return $this->u;
    }

    /**
     * @param \Uni\Domains\Share\ObjectValues\User|null $u
     */
    public function setU(?User $u): void
    {
        $this->u = $u;
    }

}

// at repository
class CreditRepository extends BaseEntityRepository
{
    public function __construct(Database $database)
    {
        // the entity class
        $entityClass = Credit::class;
        parent::__construct($entityClass, $database);
    }
}