本文整理汇总了PHP中Doctrine\ODM\MongoDB\MongoDBException::detachedDocumentCannotBeRemoved方法的典型用法代码示例。如果您正苦于以下问题:PHP MongoDBException::detachedDocumentCannotBeRemoved方法的具体用法?PHP MongoDBException::detachedDocumentCannotBeRemoved怎么用?PHP MongoDBException::detachedDocumentCannotBeRemoved使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ODM\MongoDB\MongoDBException
的用法示例。
在下文中一共展示了MongoDBException::detachedDocumentCannotBeRemoved方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doRemove
/**
* Deletes a document as part of the current unit of work.
*
* This method is internally called during delete() cascades as it tracks
* the already visited documents to prevent infinite recursions.
*
* @param object $document The document to delete.
* @param array $visited The map of the already visited documents.
* @throws MongoDBException
*/
private function doRemove($document, array &$visited)
{
$oid = spl_object_hash($document);
if (isset($visited[$oid])) {
return;
// Prevent infinite recursion
}
$visited[$oid] = $document;
// mark visited
/* Cascade first, because scheduleForDelete() removes the entity from
* the identity map, which can cause problems when a lazy Proxy has to
* be initialized for the cascade operation.
*/
$this->cascadeRemove($document, $visited);
$class = $this->dm->getClassMetadata(get_class($document));
$documentState = $this->getDocumentState($document);
switch ($documentState) {
case self::STATE_NEW:
case self::STATE_REMOVED:
// nothing to do
break;
case self::STATE_MANAGED:
if (!empty($class->lifecycleCallbacks[Events::preRemove])) {
$class->invokeLifecycleCallbacks(Events::preRemove, $document);
}
if ($this->evm->hasListeners(Events::preRemove)) {
$this->evm->dispatchEvent(Events::preRemove, new LifecycleEventArgs($document, $this->dm));
}
$this->scheduleForDelete($document);
break;
case self::STATE_DETACHED:
throw MongoDBException::detachedDocumentCannotBeRemoved();
default:
throw MongoDBException::invalidDocumentState($documentState);
}
}
示例2: doRemove
/**
* Deletes an document as part of the current unit of work.
*
* This method is internally called during delete() cascades as it tracks
* the already visited documents to prevent infinite recursions.
*
* @param object $document The document to delete.
* @param array $visited The map of the already visited documents.
* @throws InvalidArgumentException If the instance is a detached document.
*/
private function doRemove($document, array &$visited)
{
$oid = spl_object_hash($document);
if (isset($visited[$oid])) {
return;
// Prevent infinite recursion
}
$visited[$oid] = $document;
// mark visited
$class = $this->dm->getClassMetadata(get_class($document));
$documentState = $this->getDocumentState($document);
switch ($documentState) {
case self::STATE_NEW:
case self::STATE_REMOVED:
// nothing to do
break;
case self::STATE_MANAGED:
if (isset($class->lifecycleCallbacks[Events::preRemove])) {
$class->invokeLifecycleCallbacks(Events::preRemove, $document);
}
if ($this->evm->hasListeners(Events::preRemove)) {
$this->evm->dispatchEvent(Events::preRemove, new LifecycleEventArgs($document, $this->dm));
}
$this->scheduleForDelete($document);
$this->cascadePreRemove($class, $document);
break;
case self::STATE_DETACHED:
throw MongoDBException::detachedDocumentCannotBeRemoved();
default:
throw MongoDBException::invalidDocumentState($documentState);
}
$this->cascadeRemove($document, $visited);
}