本文整理汇总了PHP中Doctrine\Common\Persistence\ObjectManager::getUnitOfWork方法的典型用法代码示例。如果您正苦于以下问题:PHP ObjectManager::getUnitOfWork方法的具体用法?PHP ObjectManager::getUnitOfWork怎么用?PHP ObjectManager::getUnitOfWork使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Persistence\ObjectManager
的用法示例。
在下文中一共展示了ObjectManager::getUnitOfWork方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: persistEntities
/**
* Persists all entities managed by the repository and all cascading dependencies
*
* @return void
*/
public function persistEntities()
{
foreach ($this->entityManager->getUnitOfWork()->getIdentityMap() as $className => $entities) {
if ($className === $this->entityClassName) {
foreach ($entities as $entityToPersist) {
$this->entityManager->flush($entityToPersist);
}
return;
}
}
}
示例2: onChangeDecision
/**
* {@inheritDoc}
*/
public function onChangeDecision(SluggableAdapter $ea, array &$config, $object, &$slug, &$needToChangeSlug)
{
$this->om = $ea->getObjectManager();
$isInsert = $this->om->getUnitOfWork()->isScheduledForInsert($object);
$this->usedOptions = $config['handlers'][get_called_class()];
if (!isset($this->usedOptions['separator'])) {
$this->usedOptions['separator'] = self::SEPARATOR;
}
if (!$isInsert && !$needToChangeSlug) {
$changeSet = $ea->getObjectChangeSet($this->om->getUnitOfWork(), $object);
if (isset($changeSet[$this->usedOptions['relationField']])) {
$needToChangeSlug = true;
}
}
}
示例3: onSlugCompletion
/**
* {@inheritDoc}
*/
public function onSlugCompletion(SluggableAdapter $ea, array &$config, $object, &$slug)
{
if (!$this->isInsert) {
$options = $this->getOptions($object);
$wrapped = AbstractWrapper::wrapp($object, $this->om);
$meta = $wrapped->getMetadata();
$extConfig = $this->sluggable->getConfiguration($this->om, $meta->name);
$config['useObjectClass'] = $extConfig['useObjectClass'];
$target = $wrapped->getPropertyValue($config['slug']);
$config['pathSeparator'] = $options['separator'];
$ea->replaceRelative($object, $config, $target.$options['separator'], $slug);
$uow = $this->om->getUnitOfWork();
// update in memory objects
foreach ($uow->getIdentityMap() as $className => $objects) {
// for inheritance mapped classes, only root is always in the identity map
if ($className !== $wrapped->getRootObjectName()) {
continue;
}
foreach ($objects as $object) {
if (property_exists($object, '__isInitialized__') && !$object->__isInitialized__) {
continue;
}
$oid = spl_object_hash($object);
$objectSlug = $meta->getReflectionProperty($config['slug'])->getValue($object);
if (preg_match("@^{$target}{$options['separator']}@smi", $objectSlug)) {
$objectSlug = str_replace($target, $slug, $objectSlug);
$meta->getReflectionProperty($config['slug'])->setValue($object, $objectSlug);
$ea->setOriginalObjectProperty($uow, $oid, $config['slug'], $objectSlug);
}
}
}
}
}
示例4: setTerm
/**
* @param $term
* @throws \InvalidArgumentException
* @return $this
*/
public function setTerm($term = null)
{
$this->initialize();
if (null === $term) {
$this->entityTerm = null;
return $this;
}
if (!$term instanceof Term) {
throw new \InvalidArgumentException(sprintf('Expected instance of Term. "%s" given.', get_class($term)));
}
if ($this->em->getUnitOfWork()->getEntityState($term) == UnitOfWork::STATE_DETACHED) {
$term = $this->em->merge($term);
}
if ($term->getVocabulary() !== $this->vocabulary) {
throw new \InvalidArgumentException(sprintf('Term "%s" (#%d) does not belong in "%s" vocabulary.', $term->getName(), $term->getId(), $this->vocabulary->getName()));
}
if ($this->entityTerm && $this->entityTerm->getTerm() === $term) {
return $this;
}
$className = $this->entityTerms->getClassName();
$this->setDirty(true);
$eTerm = new $className();
/** @var $eTerm EntityTermInterface */
$eTerm->setTerm($term);
$this->entityTerm = $eTerm;
return $this;
}
示例5: hasUnpersistedChanges
/**
* Gives feedback if the persistence Manager has unpersisted changes.
*
* This is primarily used to inform the user if he tries to save
* data in an unsafe request.
*
* @return boolean
*/
public function hasUnpersistedChanges()
{
$unitOfWork = $this->entityManager->getUnitOfWork();
if ($unitOfWork->getScheduledEntityInsertions() !== array() || $unitOfWork->getScheduledEntityUpdates() !== array() || $unitOfWork->getScheduledEntityDeletions() !== array() || $unitOfWork->getScheduledCollectionDeletions() !== array() || $unitOfWork->getScheduledCollectionUpdates() !== array()) {
return TRUE;
}
return FALSE;
}
示例6: hasUnpersistedChanges
/**
* Gives feedback if the persistence Manager has unpersisted changes.
*
* This is primarily used to inform the user if he tries to save
* data in an unsafe request.
*
* @return boolean
*/
public function hasUnpersistedChanges()
{
$unitOfWork = $this->entityManager->getUnitOfWork();
$unitOfWork->computeChangeSets();
if ($unitOfWork->getScheduledEntityInsertions() !== [] || $unitOfWork->getScheduledEntityUpdates() !== [] || $unitOfWork->getScheduledEntityDeletions() !== [] || $unitOfWork->getScheduledCollectionDeletions() !== [] || $unitOfWork->getScheduledCollectionUpdates() !== []) {
return true;
}
return false;
}
示例7: onSlugCompletion
/**
* {@inheritDoc}
*/
public function onSlugCompletion(SluggableAdapter $ea, array &$config, $object, &$slug)
{
$this->om = $ea->getObjectManager();
$isInsert = $this->om->getUnitOfWork()->isScheduledForInsert($object);
if (!$isInsert) {
$options = $config['handlers'][get_called_class()];
$wrapped = AbstractWrapper::wrapp($object, $this->om);
$oldSlug = $wrapped->getPropertyValue($config['slug']);
$mappedByConfig = $this->sluggable->getConfiguration($this->om, $options['relationClass']);
if ($mappedByConfig) {
$meta = $this->om->getClassMetadata($options['relationClass']);
if (!$meta->isSingleValuedAssociation($options['mappedBy'])) {
throw new InvalidMappingException("Unable to find " . $wrapped->getMetadata()->name . " relation - [{$options['mappedBy']}] in class - {$meta->name}");
}
if (!isset($mappedByConfig['slugs'][$options['inverseSlugField']])) {
throw new InvalidMappingException("Unable to find slug field - [{$options['inverseSlugField']}] in class - {$meta->name}");
}
$mappedByConfig['slug'] = $mappedByConfig['slugs'][$options['inverseSlugField']]['slug'];
$mappedByConfig['mappedBy'] = $options['mappedBy'];
$ea->replaceInverseRelative($object, $mappedByConfig, $slug, $oldSlug);
$uow = $this->om->getUnitOfWork();
// update in memory objects
foreach ($uow->getIdentityMap() as $className => $objects) {
// for inheritance mapped classes, only root is always in the identity map
if ($className !== $mappedByConfig['useObjectClass']) {
continue;
}
foreach ($objects as $object) {
if (property_exists($object, '__isInitialized__') && !$object->__isInitialized__) {
continue;
}
$oid = spl_object_hash($object);
$objectSlug = $meta->getReflectionProperty($mappedByConfig['slug'])->getValue($object);
if (preg_match("@^{$oldSlug}@smi", $objectSlug)) {
$objectSlug = str_replace($oldSlug, $slug, $objectSlug);
$meta->getReflectionProperty($mappedByConfig['slug'])->setValue($object, $objectSlug);
$ea->setOriginalObjectProperty($uow, $oid, $mappedByConfig['slug'], $objectSlug);
}
}
}
}
}
}
示例8: hasIdentifier
/**
* Checks if object has identifier already in unit of work.
*
* @param $reference
*
* @return bool
*/
private function hasIdentifier($reference)
{
// in case if reference is set after flush, store its identity
$uow = $this->manager->getUnitOfWork();
if ($this->manager instanceof PhpcrDocumentManager) {
return $uow->contains($reference);
} else {
return $uow->isInIdentityMap($reference);
}
}
示例9: changed
/**
* Schedule update of the owner in the unit of work
*/
private function changed()
{
if (null === $this->manager) {
$this->manager = $this->registry->getManagerForClass(ClassUtils::getClass($this->owner));
}
$uow = $this->manager->getUnitOfWork();
if (UnitOfWork::STATE_MANAGED === $uow->getDocumentState($this->owner) && !$uow->isScheduledForUpdate($this->owner)) {
$uow->scheduleForUpdate($this->owner);
}
}
示例10: sendEvent
/**
* send created event.
*
* @param $version
*/
public function sendEvent($version)
{
$entityInsertions = $this->manager->getUnitOfWork()->getScheduledEntityInsertions();
foreach ($entityInsertions as $entityInsertion) {
$this->dispatchEvent($entityInsertion, Events::PRE_CREATE, $version);
}
$this->manager->getUnitOfWork()->computeChangeSets();
$entityUpdateds = $this->manager->getUnitOfWork()->getScheduledEntityUpdates();
foreach ($entityUpdateds as $entityUpdated) {
$this->dispatchEvent($entityUpdated, Events::PRE_UPDATE, $version);
}
}
示例11: onChangeDecision
/**
* {@inheritDoc}
*/
public function onChangeDecision(SluggableAdapter $ea, $slugFieldConfig, $object, &$slug, &$needToChangeSlug)
{
$this->om = $ea->getObjectManager();
$isInsert = $this->om->getUnitOfWork()->isScheduledForInsert($object);
if (!$isInsert && !$needToChangeSlug) {
$changeSet = $ea->getObjectChangeSet($this->om->getUnitOfWork(), $object);
$options = $this->getOptions($object);
if (isset($changeSet[$options['relationField']])) {
$needToChangeSlug = true;
}
}
}
示例12: checkType
/**
* @param $element
* @throws \InvalidArgumentException
*/
protected function checkType($element)
{
if (!$element instanceof Term) {
throw new \InvalidArgumentException(sprintf('Expected instance of %s. "%s" given.', __NAMESPACE__ . '\\Term', get_class($element)));
}
if ($this->em->getUnitOfWork()->getEntityState($element) == UnitOfWork::STATE_DETACHED) {
$element = $this->em->merge($element);
}
if ($element->getVocabulary() !== $this->vocabulary) {
throw new \InvalidArgumentException(sprintf('Term "%s" (#%d) does not belong in the "%s" vocabulary.', $element->getName(), $element->getId(), $this->vocabulary->getName()));
}
}
示例13: getReference
/**
* Loads an object using stored reference
* named by $name
*
* @param string $name
* @return object
*/
public function getReference($name)
{
$reference = $this->references[$name];
$meta = $this->manager->getClassMetadata(get_class($reference));
$uow = $this->manager->getUnitOfWork();
if (!$uow->isInIdentityMap($reference) && isset($this->identities[$name])) {
$reference = $this->manager->getReference($meta->name, $this->identities[$name]);
$this->references[$name] = $reference;
// allready in identity map
}
return $reference;
}
示例14: saveEntity
/**
* Save an entity
*
* @param object $node
* @param boolean $andFlush
*/
protected function saveEntity($entity, $andFlush = true)
{
if ($this->objectManager->getUnitOfWork()->getEntityState($entity) == \Doctrine\ORM\UnitOfWork::STATE_NEW) {
return $this->createEntity($entity, $andFlush);
} else {
$em = $this->objectManager;
$em->persist($entity);
if ($andFlush) {
$em->flush();
}
}
}
示例15: persistEntities
/**
* Persists all entities managed by the repository and all cascading dependencies
*
* @return void
*/
public function persistEntities()
{
foreach ($this->entityManager->getUnitOfWork()->getIdentityMap() as $className => $entities) {
if ($className === $this->entityClassName) {
foreach ($entities as $entityToPersist) {
$this->entityManager->flush($entityToPersist);
}
$this->emitRepositoryObjectsPersisted();
break;
}
}
}