當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ClassMetadata::invokeLifecycleCallbacks方法代碼示例

本文整理匯總了PHP中Doctrine\ODM\MongoDB\Mapping\ClassMetadata::invokeLifecycleCallbacks方法的典型用法代碼示例。如果您正苦於以下問題:PHP ClassMetadata::invokeLifecycleCallbacks方法的具體用法?PHP ClassMetadata::invokeLifecycleCallbacks怎麽用?PHP ClassMetadata::invokeLifecycleCallbacks使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Doctrine\ODM\MongoDB\Mapping\ClassMetadata的用法示例。


在下文中一共展示了ClassMetadata::invokeLifecycleCallbacks方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: executeDeletions

 /**
  * Executes all document deletions for documents of the specified type.
  *
  * @param ClassMetadata $class
  * @param array $documents Array of documents to delete
  * @param array $options Array of options to be used with remove()
  */
 private function executeDeletions(ClassMetadata $class, array $documents, array $options = array())
 {
     $hasPostRemoveLifecycleCallbacks = !empty($class->lifecycleCallbacks[Events::postRemove]);
     $hasPostRemoveListeners = $this->evm->hasListeners(Events::postRemove);
     $persister = $this->getDocumentPersister($class->name);
     foreach ($documents as $oid => $document) {
         if (!$class->isEmbeddedDocument) {
             $persister->delete($document, $options);
         }
         unset($this->documentDeletions[$oid], $this->documentIdentifiers[$oid], $this->originalDocumentData[$oid]);
         // Clear snapshot information for any referenced PersistentCollection
         // http://www.doctrine-project.org/jira/browse/MODM-95
         foreach ($class->associationMappings as $fieldMapping) {
             if (isset($fieldMapping['type']) && $fieldMapping['type'] === ClassMetadata::MANY) {
                 $value = $class->reflFields[$fieldMapping['fieldName']]->getValue($document);
                 if ($value instanceof PersistentCollection) {
                     $value->clearSnapshot();
                 }
             }
         }
         // Document with this $oid after deletion treated as NEW, even if the $oid
         // is obtained by a new document because the old one went out of scope.
         $this->documentStates[$oid] = self::STATE_NEW;
         if ($hasPostRemoveLifecycleCallbacks) {
             $class->invokeLifecycleCallbacks(Events::postRemove, $document);
         }
         if ($hasPostRemoveListeners) {
             $this->evm->dispatchEvent(Events::postRemove, new LifecycleEventArgs($document, $this->dm));
         }
     }
 }
開發者ID:kevinyien,項目名稱:mongodb-odm,代碼行數:38,代碼來源:UnitOfWork.php

示例2: _executeDeletions

 /**
  * Executes all document deletions for documents of the specified type.
  *
  * @param Doctrine\ODM\MongoDB\Mapping\ClassMetadata $class
  */
 private function _executeDeletions($class)
 {
     $hasLifecycleCallbacks = isset($class->lifecycleCallbacks[Events::postRemove]);
     $hasListeners = $this->_evm->hasListeners(Events::postRemove);
     $className = $class->name;
     $persister = $this->getDocumentPersister($className);
     $collection = $this->_dm->getDocumentCollection($className);
     foreach ($this->_documentDeletions as $oid => $document) {
         if (get_class($document) == $className || $document instanceof Proxy && $document instanceof $className) {
             $persister->delete($document);
             unset($this->_documentDeletions[$oid], $this->_documentIdentifiers[$oid], $this->_originalDocumentData[$oid]);
             // Document with this $oid after deletion treated as NEW, even if the $oid
             // is obtained by a new document because the old one went out of scope.
             $this->_documentStates[$oid] = self::STATE_NEW;
             if ($hasLifecycleCallbacks) {
                 $class->invokeLifecycleCallbacks(Events::postRemove, $document);
             }
             if ($hasListeners) {
                 $this->_evm->dispatchEvent(Events::postRemove, new LifecycleEventArgs($document, $this->_dm));
             }
         }
     }
 }
開發者ID:bzarzuela,項目名稱:Doctrine-2-Blog-Example,代碼行數:28,代碼來源:UnitOfWork.php

示例3: executeInserts

 /**
  * Executes all document insertions for documents of the specified type.
  *
  * @param Doctrine\ODM\MongoDB\Mapping\ClassMetadata $class
  * @param array $options Array of options to be used with batchInsert()
  */
 private function executeInserts($class, array $options = array())
 {
     $className = $class->name;
     $persister = $this->getDocumentPersister($className);
     $collection = $this->dm->getDocumentCollection($className);
     $hasLifecycleCallbacks = isset($class->lifecycleCallbacks[Events::postPersist]);
     $hasListeners = $this->evm->hasListeners(Events::postPersist);
     if ($hasLifecycleCallbacks || $hasListeners) {
         $documents = array();
     }
     $inserts = array();
     foreach ($this->documentInsertions as $oid => $document) {
         if (get_class($document) === $className) {
             $persister->addInsert($document);
             unset($this->documentInsertions[$oid]);
             if ($hasLifecycleCallbacks || $hasListeners) {
                 $documents[] = $document;
             }
         }
     }
     $postInsertIds = $persister->executeInserts($options);
     if ($postInsertIds) {
         foreach ($postInsertIds as $pair) {
             list($id, $document) = $pair;
             $oid = spl_object_hash($document);
             $class->setIdentifierValue($document, $id);
             $this->documentIdentifiers[$oid] = $id;
             $this->documentStates[$oid] = self::STATE_MANAGED;
             $this->originalDocumentData[$oid][$class->identifier] = $id;
             $this->addToIdentityMap($document);
             if ($hasLifecycleCallbacks || $hasListeners) {
                 if ($hasLifecycleCallbacks) {
                     $class->invokeLifecycleCallbacks(Events::postPersist, $document);
                 }
                 if ($hasListeners) {
                     $this->evm->dispatchEvent(Events::postPersist, new LifecycleEventArgs($document, $this->dm));
                 }
             }
             $this->cascadePostPersist($class, $document);
         }
     }
 }
開發者ID:nextmotion,項目名稱:mongodb-odm,代碼行數:48,代碼來源:UnitOfWork.php

示例4: preUpdate

 /**
  * Invokes preUpdate callbacks and events for given document cascading them to embedded documents as well.
  *
  * @param ClassMetadata $class
  * @param object $document
  */
 public function preUpdate(ClassMetadata $class, $document)
 {
     if (!empty($class->lifecycleCallbacks[Events::preUpdate])) {
         $class->invokeLifecycleCallbacks(Events::preUpdate, $document, array(new PreUpdateEventArgs($document, $this->dm, $this->uow->getDocumentChangeSet($document))));
         $this->uow->recomputeSingleDocumentChangeSet($class, $document);
     }
     $this->evm->dispatchEvent(Events::preUpdate, new PreUpdateEventArgs($document, $this->dm, $this->uow->getDocumentChangeSet($document)));
     $this->cascadePreUpdate($class, $document);
 }
開發者ID:alcaeus,項目名稱:mongodb-odm,代碼行數:15,代碼來源:LifecycleEventManager.php


注:本文中的Doctrine\ODM\MongoDB\Mapping\ClassMetadata::invokeLifecycleCallbacks方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。