本文整理汇总了PHP中Doctrine\Common\Persistence\ObjectManager::contains方法的典型用法代码示例。如果您正苦于以下问题:PHP ObjectManager::contains方法的具体用法?PHP ObjectManager::contains怎么用?PHP ObjectManager::contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Persistence\ObjectManager
的用法示例。
在下文中一共展示了ObjectManager::contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doUpdate
/**
* {@inheritdoc}
*/
protected function doUpdate($object, $flush = true)
{
if (!$this->manager->contains($object)) {
$this->manager->persist($object);
}
if ($flush) {
$this->flush($object);
}
}
示例2: handle
/**
* {@inheritdoc}
*/
public function handle(ApiCallInterface $apiCall)
{
if (!$this->objectManager->contains($apiCall)) {
if ($apiCall->getId() === null) {
$this->objectManager->persist($apiCall);
} else {
$this->objectManager->merge($apiCall);
}
}
$this->objectManager->flush();
}
示例3: update
/**
* {@inheritdoc}
*/
public function update(Content $content)
{
$managed = true;
if (!$this->om->contains($content)) {
$managed = false;
$content = $this->om->merge($content);
}
$this->om->flush($content);
if (!$managed) {
$this->om->detach($content);
}
}
示例4: getIdentifierValues
/**
* Returns the values of the identifier fields of an entity.
*
* Doctrine must know about this entity, that is, the entity must already
* be persisted or added to the identity map before. Otherwise an
* exception is thrown.
*
* @param object $entity The entity for which to get the identifier
*
* @return array The identifier values
*
* @throws FormException If the entity does not exist in Doctrine's identity map
*/
public function getIdentifierValues($entity)
{
if (!$this->em->contains($entity)) {
throw new FormException('Entities passed to the choice field must be managed');
}
return $this->classMetadata->getIdentifierValues($entity);
}
示例5:
function it_can_handle_exiting_unmanaged_objects(ObjectManager $objectManager, ApiCallInterface $apiCall)
{
$objectManager->contains($apiCall)->willReturn(false);
$apiCall->getId()->willReturn(1);
$objectManager->merge($apiCall)->shouldBeCalled();
$objectManager->flush()->shouldBeCalled();
$this->handle($apiCall);
}
示例6: getIdentifierValues
/**
* Returns the values of the identifier fields of an entity.
*
* Doctrine must know about this entity, that is, the entity must already
* be persisted or added to the identity map before. Otherwise an
* exception is thrown.
*
* @param object $entity The entity for which to get the identifier
*
* @return array The identifier values
*
* @throws Exception If the entity does not exist in Doctrine's identity map
*/
private function getIdentifierValues($entity)
{
if (!$this->em->contains($entity)) {
throw new Exception('Entities passed to the choice field must be managed. Maybe ' . 'persist them in the entity manager?');
}
$this->em->initializeObject($entity);
return $this->classMetadata->getIdentifierValues($entity);
}
示例7: getIdValue
/**
* Returns the ID value for an object.
*
* This method assumes that the object has a single-column ID.
*
* @param object $object The object.
*
* @return mixed The ID value.
*/
public function getIdValue($object)
{
if (!$object) {
return;
}
if (!$this->om->contains($object)) {
throw new RuntimeException('Entities passed to the choice field must be managed. Maybe ' . 'persist them in the entity manager?');
}
$this->om->initializeObject($object);
return current($this->classMetadata->getIdentifierValues($object));
}
示例8: getReference
/**
* Loads an object using stored reference
* named by $name
*
* @param string $name
* @throws OutOfBoundsException - if repository does not exist
* @return object
*/
public function getReference($name)
{
if (!$this->hasReference($name)) {
throw new \OutOfBoundsException("Reference to: ({$name}) does not exist");
}
$reference = $this->references[$name];
$meta = $this->manager->getClassMetadata(get_class($reference));
if (!$this->manager->contains($reference) && isset($this->identities[$name])) {
$reference = $this->manager->getReference($meta->name, $this->identities[$name]);
$this->references[$name] = $reference;
// already in identity map
}
return $reference;
}
示例9: getIdentifierByObject
/**
* Returns the (internal) identifier for the object, if it is known to the
* backend. Otherwise NULL is returned.
*
* Note: this returns an identifier even if the object has not been
* persisted in case of AOP-managed entities. Use isNewObject() if you need
* to distinguish those cases.
*
* @param object $object
* @return mixed The identifier for the object if it is known, or NULL
* @api
* @todo improve try/catch block
*/
public function getIdentifierByObject($object)
{
if ($this->entityManager->contains($object)) {
try {
return current($this->entityManager->getUnitOfWork()->getEntityIdentifier($object));
} catch (\Doctrine\ORM\ORMException $e) {
return NULL;
}
} elseif (property_exists($object, 'FLOW3_Persistence_Identifier')) {
return \TYPO3\FLOW3\Reflection\ObjectAccess::getProperty($object, 'FLOW3_Persistence_Identifier', TRUE);
} else {
return NULL;
}
}
示例10: getIdentifierByObject
/**
* Returns the (internal) identifier for the object, if it is known to the
* backend. Otherwise NULL is returned.
*
* Note: this returns an identifier even if the object has not been
* persisted in case of AOP-managed entities. Use isNewObject() if you need
* to distinguish those cases.
*
* @param object $object
* @return mixed The identifier for the object if it is known, or NULL
* @api
* @todo improve try/catch block
*/
public function getIdentifierByObject($object)
{
if (property_exists($object, 'Persistence_Object_Identifier')) {
$identifierCandidate = ObjectAccess::getProperty($object, 'Persistence_Object_Identifier', true);
if ($identifierCandidate !== null) {
return $identifierCandidate;
}
}
if ($this->entityManager->contains($object)) {
try {
return current($this->entityManager->getUnitOfWork()->getEntityIdentifier($object));
} catch (\Doctrine\ORM\ORMException $exception) {
}
}
return null;
}
示例11: getIdentifierByObject
/**
* Returns the (internal) identifier for the object, if it is known to the
* backend. Otherwise NULL is returned.
*
* Note: this returns an identifier even if the object has not been
* persisted in case of AOP-managed entities. Use isNewObject() if you need
* to distinguish those cases.
*
* @param object $object
* @return mixed The identifier for the object if it is known, or NULL
* @api
* @todo improve try/catch block
*/
public function getIdentifierByObject($object)
{
if (property_exists($object, 'Persistence_Object_Identifier')) {
$identifierCandidate = \TYPO3\Flow\Reflection\ObjectAccess::getProperty($object, 'Persistence_Object_Identifier', TRUE);
if ($identifierCandidate !== NULL) {
return $identifierCandidate;
}
}
if ($this->entityManager->contains($object)) {
try {
return current($this->entityManager->getUnitOfWork()->getEntityIdentifier($object));
} catch (\Doctrine\ORM\ORMException $e) {
}
}
return NULL;
}
示例12: refreshUser
/**
* (non-PHPdoc)
*
* @see \Symfony\Component\Security\Core\User\UserProviderInterface::refreshUser()
*/
public function refreshUser(UserInterface $user)
{
$userClass = get_class($user);
if (!$this->supportsClass($userClass)) {
throw new UnsupportedUserException("Unsupported user '" . $userClass . "'");
}
/* @var ADH\UserBundle\Entity\User $user */
if ($this->entityManager->contains($user)) {
$this->entityManager->refresh($user);
} else {
$user = $this->userRepository->findOneById($user->getId());
}
if ($user === null) {
throw new UsernameNotFoundException("User does not exist.");
}
return $user;
}
示例13: supports
/**
* {@inheritDoc}
*/
public function supports($object)
{
return $this->om->contains($object);
}
示例14: recomputeSingleObjectChangeSet
/**
* @param ObjectManager|DocumentManager|EntityManager $om
* @param object $object
*/
protected function recomputeSingleObjectChangeSet(ObjectManager $om, $object)
{
if ($om->contains($object)) {
$classMetadata = $om->getClassMetadata(get_class($object));
$uow = $om->getUnitOfWork();
if ($uow instanceof ODMUnitOfWork) {
$uow->recomputeSingleDocumentChangeSet($classMetadata, $object);
} elseif ($uow instanceof ORMUnitOfWork) {
$uow->recomputeSingleEntityChangeSet($classMetadata, $object);
}
}
}
示例15: computeViolations
/**
* @param object $entity entity
* @param ObjectManager $entityManager entityManager
* @param UnitOfWork $uow uow
*/
private function computeViolations($entity, ObjectManager $entityManager, UnitOfWork $uow)
{
if (!($handlers = $this->handlerManager->fetch($entity))) {
return null;
}
$list = $this->violationManager->getViolationListNotFixed($entity);
$list->setFixed(true);
foreach ($handlers as $handler) {
$handler->validate($entity, $list);
}
$uow->computeChangeSets();
foreach ($list as $violation) {
$changeSet = $uow->getEntityChangeSet($violation);
if (!empty($changeSet) || !$entityManager->contains($violation)) {
$this->violations[spl_object_hash($violation)] = $violation;
}
}
}