Sokil\Mongo\Document::__construct PHP 메소드

__construct() 공개 메소드

public __construct ( Collection $collection, array $data = null, array $options = [] )
$collection Collection instance of Mongo collection
$data array mongo document
$options array options of object initialization
    public function __construct(Collection $collection, array $data = null, array $options = array())
    {
        // lisk to collection
        $this->collection = $collection;
        // configure document with options
        $this->options = $options;
        // init document
        $this->initDelegates();
        // execute before construct callable
        $this->beforeConstruct();
        // initialize with data
        parent::__construct($data, $this->getOption('stored'));
        // use versioning
        if ($this->getOption('versioning')) {
            $this->getRevisionManager()->listen();
        }
        // execure after construct event handlers
        $this->eventDispatcher->dispatch('afterConstruct');
    }

Usage Example

예제 #1
0
 public function __construct(Collection $revisionsCollection, array $data = null, array $options = array())
 {
     parent::__construct($revisionsCollection, $data, $options);
     $baseCollectionName = substr($revisionsCollection->getName(), 0, -1 * strlen(RevisionManager::REVISION_COLLECTION_SUFFIX));
     $this->baseCollection = $revisionsCollection->getDatabase()->getCollection($baseCollectionName);
 }