public __construct ( array $data = null, boolean | true $notModified = true ) | ||
$data | array | data to initialise structure |
$notModified | boolean | true | define if data set as modified or not |
public function __construct(array $data = null, $notModified = true)
{
// self::$data and self::$schema instead of deprecated self::$_data
if ($this->_data) {
$this->schema = $this->_data;
}
$this->_data =& $this->data;
// define initial data with schema
$this->data = $this->schema;
$this->originalData = $this->data;
// initialize with passed data
if ($data) {
if ($notModified) {
// set as not modified
$this->replace($data);
} else {
// set as modified
$this->merge($data);
}
}
}
/** * @param \Sokil\Mongo\Collection $collection instance of Mongo collection * @param array $data mongo document * @param array $options 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'); }