本文整理汇总了PHP中Doctrine\ORM\UnitOfWork::getEntityState方法的典型用法代码示例。如果您正苦于以下问题:PHP UnitOfWork::getEntityState方法的具体用法?PHP UnitOfWork::getEntityState怎么用?PHP UnitOfWork::getEntityState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\UnitOfWork
的用法示例。
在下文中一共展示了UnitOfWork::getEntityState方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isValidEntityState
/**
* Check if entity is in a valid state for operations.
*
* @param object $entity
*
* @return bool
*/
protected function isValidEntityState($entity)
{
$entityState = $this->uow->getEntityState($entity, UnitOfWork::STATE_NEW);
if ($entityState === UnitOfWork::STATE_NEW) {
return false;
}
// If Entity is scheduled for inclusion, it is not in this collection.
// We can assure that because it would have return true before on array check
return !($entityState === UnitOfWork::STATE_MANAGED && $this->uow->isScheduledForInsert($entity));
}
示例2: isNewEntity
/**
* @param object $entity
* @param UnitOfWork $uow
*
* @return bool
*/
protected function isNewEntity($entity, UnitOfWork $uow)
{
$entityState = $uow->getEntityState($entity);
return $entityState !== UnitOfWork::STATE_NEW && $entityState !== UnitOfWork::STATE_DETACHED && !$uow->isScheduledForInsert($entity);
}
示例3: getIdString
/**
* @param object $entity
* @param UnitOfWork $uow
*
* @return string
*/
private function getIdString($entity, UnitOfWork $uow)
{
if ($uow->isInIdentityMap($entity)) {
$ids = $uow->getEntityIdentifier($entity);
$idstring = "";
foreach ($ids as $k => $v) {
$idstring .= $k . "=" . $v;
}
} else {
$idstring = "NEWOBJECT ";
}
$state = $uow->getEntityState($entity);
if ($state == UnitOfWork::STATE_NEW) {
$idstring .= " [NEW]";
} elseif ($state == UnitOfWork::STATE_REMOVED) {
$idstring .= " [REMOVED]";
} elseif ($state == UnitOfWork::STATE_MANAGED) {
$idstring .= " [MANAGED]";
} elseif ($state == UnitOfwork::STATE_DETACHED) {
$idstring .= " [DETACHED]";
}
return $idstring;
}
示例4: generatePath
/**
* Generates new full path and validates its uniqueness
* @param PageLocalization $pageData
* @return PageLocalization if changes were made
*/
protected function generatePath(PageLocalization $pageData, $force = false)
{
$page = $pageData->getMaster();
$oldPath = $pageData->getPath();
$changes = false;
$oldPathEntity = $pageData->getPathEntity();
list($newPath, $active, $limited, $inSitemap) = $this->findPagePath($pageData);
if (!$page->isRoot()) {
if (!Path::compare($oldPath, $newPath) || $force) {
$suffix = null;
// Check duplicates only if path is not null
if (!is_null($newPath)) {
// Additional check for path length
$pathString = $newPath->getPath();
if (mb_strlen($pathString) > 255) {
throw new Exception\RuntimeException('Overall path length shouldn\'t be more than 255 symbols');
}
$i = 2;
$e = null;
$pathPart = $pageData->getPathPart();
$pathValid = false;
do {
try {
$this->checkForDuplicates($pageData, $newPath);
$pathValid = true;
} catch (DuplicatePagePathException $e) {
if ($force) {
// loop stoper
if ($i > 101) {
throw new Exception\RuntimeException("Couldn't find unique path for new page", null, $e);
}
// Will try adding unique suffix after 100 iterations
if ($i > 100) {
$suffix = uniqid();
} else {
$suffix = $i;
}
$pageData->setPathPart($pathPart . '-' . $suffix);
list($newPath, $active, $limited, $inSitemap) = $this->findPagePath($pageData);
$i++;
}
}
} while ($force && !$pathValid);
if ($e instanceof DuplicatePagePathException && !$pathValid) {
throw $e;
}
}
// Validation passed, set the new path
$pageData->setPathData($newPath, $active, $limited, $inSitemap);
if (!is_null($suffix)) {
$pageData->setTitle($pageData->getTitle() . " ({$suffix})");
}
$changes = true;
}
} elseif ($page->getLeftValue() == 1) {
$newPath = new Path('');
// Root page
if (!$newPath->equals($oldPath)) {
$changes = true;
$pageData->setPathData($newPath, $active, $limited, $inSitemap);
}
// Another root page...
} else {
$newPath = null;
$active = false;
$pageData->setPathData($newPath, $active, $limited, $inSitemap);
}
if ($oldPathEntity->isActive() !== $active || $oldPathEntity->isVisibleInSitemap() != $inSitemap) {
$pageData->setPathData($newPath, $active, $limited, $inSitemap);
$changes = true;
}
if ($changes) {
$pathEntity = $pageData->getPathEntity();
$pathMetaData = $this->em->getClassMetadata($pathEntity->CN());
$localizationMetaData = $this->em->getClassMetadata($pageData->CN());
if ($this->unitOfWork->getEntityState($pathEntity, UnitOfWork::STATE_NEW) === UnitOfWork::STATE_NEW) {
$this->em->persist($pathEntity);
// } elseif ($this->unitOfWork->getEntityState($pathEntity) === UnitOfWork::STATE_DETACHED) {
// $pathEntity = $this->em->merge($pathEntity);
}
/*
* Add the path changes to the changeset, must call different
* methods depending on is the entity inside the unit of work
* changeset
*/
if ($this->unitOfWork->getEntityChangeSet($pathEntity)) {
$this->unitOfWork->recomputeSingleEntityChangeSet($pathMetaData, $pathEntity);
} else {
$this->unitOfWork->computeChangeSet($pathMetaData, $pathEntity);
}
if ($this->unitOfWork->getEntityChangeSet($pageData)) {
$this->unitOfWork->recomputeSingleEntityChangeSet($localizationMetaData, $pageData);
} else {
$this->unitOfWork->computeChangeSet($localizationMetaData, $pageData);
}
//.........这里部分代码省略.........