/** * Initializes the collection by loading its contents from the database * if the collection is not yet initialized. */ public function initialize() { if (!$this->initialized && $this->mapping) { if ($this->isDirty) { // Has NEW objects added through add(). Remember them. $newObjects = $this->coll->toArray(); } $this->coll->clear(); $this->uow->loadCollection($this); $this->takeSnapshot(); // Reattach NEW objects added through add(), if any. if (isset($newObjects)) { foreach ($newObjects as $key => $obj) { if ($this->mapping['strategy'] === 'set') { $this->coll->set($key, $obj); } else { $this->coll->add($obj); } } $this->isDirty = true; } $this->mongoData = array(); $this->initialized = true; } }