当前位置: 首页>>代码示例>>PHP>>正文


PHP EntityManager::contains方法代码示例

本文整理汇总了PHP中Doctrine\ORM\EntityManager::contains方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityManager::contains方法的具体用法?PHP EntityManager::contains怎么用?PHP EntityManager::contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\ORM\EntityManager的用法示例。


在下文中一共展示了EntityManager::contains方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: processForm

 /**
  * Processes the form and build the Response object
  *
  * @param Request $request
  * @param Organization $organization
  * @return Response|static
  * @throws BadRequestHttpException
  */
 public function processForm(Request $request, Organization $organization)
 {
     $statusCode = !$this->em->contains($organization) ? 201 : 204;
     $form = $this->container->get('form.factory')->create(OrganizationType::class, $organization);
     $formData = json_decode($request->getContent(), true);
     $form->submit($this->prepareFormData($formData));
     if (!$form->isValid()) {
         return View::create($form, 400);
     }
     if (!$this->em->contains($organization)) {
         $this->em->persist($organization);
     }
     try {
         $this->em->flush();
     } catch (\Exception $e) {
         $pdoException = $e->getPrevious();
         // unique constraint
         if ($pdoException->getCode() === '23000') {
             throw new BadRequestHttpException('Error 23000!');
         }
         throw new BadRequestHttpException('Unknown error code: ' . $pdoException->getCode());
     }
     $response = new Response();
     $response->setStatusCode($statusCode);
     if (201 === $statusCode) {
         $response->headers->set('Access-Control-Expose-Headers', 'Location');
         $response->headers->set('Location', $this->container->get('router')->generate('api_v1_get_organization', ['organization' => $organization->getId()], UrlGeneratorInterface::RELATIVE_PATH));
     }
     return $response;
 }
开发者ID:schnitzel25,项目名称:api,代码行数:38,代码来源:OrganizationsHelpers.php

示例2: onClear

 /**
  * 
  */
 public function onClear(\Doctrine\Common\EventArgs $args)
 {
     foreach ($this->array as $entity) {
         if (!$this->entityManager->contains($entity)) {
             $entity->free();
         }
     }
 }
开发者ID:sitesupra,项目名称:sitesupra,代码行数:11,代码来源:DoctrineRepositoryArrayHelper.php

示例3: persistEntity

 /**
  * @param $entity
  */
 private function persistEntity($entity)
 {
     if ($this->isEntity($entity)) {
         if (!$this->em->contains($entity)) {
             $this->em->persist($entity);
             $this->persistAllAssociations($entity);
         }
     }
 }
开发者ID:bitecodes,项目名称:factrine-bundle,代码行数:12,代码来源:PersistenceHelper.php

示例4: iHaveAValidAccessToken

 /**
  * @Given I have a valid :role access token
  *
  * @param $role
  * @param null $email
  */
 public function iHaveAValidAccessToken($role, $email = null)
 {
     $user = $this->userFixtureContext->generateDefaultUser($role, $email);
     if (!$this->entityManager->contains($user)) {
         $this->entityManager->persist($user);
     }
     $this->entityManager->flush();
     $token = $this->generateAccessToken($user);
     $this->setAuthorizationBearerHeader($token);
 }
开发者ID:interactive-solutions,项目名称:zf-behat,代码行数:16,代码来源:ZfrOAuthContext.php

示例5: save

 /**
  * Savely persist Doctrine 2 Entity information
  *
  * @param ezcWorkflowExecution $execution
  * @param string $variableName
  * @param  $value
  */
 public function save(ezcWorkflowExecution $execution, $variableName, $value)
 {
     if (!is_object($value)) {
         return null;
     }
     if (!$this->em->contains($value)) {
         throw new \ezcWorkflowExecutionException("Entity '" . get_class($value) . "' at variable " . $variableName . " has to be managed by the EntityManager.");
     }
     $entityData = array(get_class($value), $this->em->getUnitOfWork()->getEntityIdentifier($value));
     $entityDetailsVariable = $variableName . "_dc2entity";
     $execution->setVariable($entityDetailsVariable, $entityData);
     $execution->setVariable($variableName, null);
 }
开发者ID:beberlei,项目名称:Doctrine-Workflow,代码行数:20,代码来源:EntityManagerHandler.php

示例6: processForm

 /**
  * Processes the form and build the Response object
  *
  * @param Request $request
  * @param Organization $department
  * @param Setting $setting
  * @return Response|static
  * @throws BadRequestHttpException
  */
 public function processForm(Request $request, Organization $department, Setting $setting)
 {
     $statusCode = $this->em->contains($setting) ? 204 : 201;
     $form = $this->container->get('form.factory')->create(SettingType::class, $setting);
     $formData = json_decode($request->getContent(), true);
     $form->submit($this->prepareFormData($formData));
     if (!$form->isValid()) {
         return View::create($form, 400);
     }
     if (!$this->em->contains($setting)) {
         $setting->setDepartment($department);
         $this->em->persist($setting);
     }
     try {
         $this->em->flush();
     } catch (\Exception $e) {
         throw new BadRequestHttpException();
     }
     $response = new Response();
     $response->setStatusCode($statusCode);
     if (201 === $statusCode) {
         $response->headers->set('Access-Control-Expose-Headers', 'Location');
         $response->headers->set('Location', $this->container->get('router')->generate('api_v1_get_organization_departments_settings', ['organization' => $department->getOrganization()->getId(), 'department' => $department->getId(), 'setting' => $setting->getId()], UrlGeneratorInterface::RELATIVE_PATH));
     }
     return $response;
 }
开发者ID:schnitzel25,项目名称:api,代码行数:35,代码来源:SettingsHelpers.php

示例7: saveEntity

 /**
  * Saves the entity.
  *
  * @param object $entity
  * @return bool
  */
 public function saveEntity($entity)
 {
     if (!$this->entityManager->contains($entity)) {
         $this->entityManager->persist($entity);
     }
     $this->entityManager->flush();
     return true;
 }
开发者ID:gibilogic,项目名称:crud-bundle,代码行数:14,代码来源:EntityService.php

示例8: getContentValue

 /**
  * Returns the indexed value of an element.
  * 
  * @param  AbstractClassContent $content        The content flushed.
  * @param  string               $indexedElement The parameter to index.
  * 
  * @return array                                An array of the element value and the content owner.
  */
 private static function getContentValue(AbstractClassContent $content, $indexedElement)
 {
     $value = $owner = $content;
     $elements = explode('->', $indexedElement);
     foreach ($elements as $element) {
         $value = $value->getData($element);
         if (!$value instanceof AbstractClassContent) {
             break;
         }
         if (!self::$em->contains($value)) {
             $value = self::$em->find(get_class($value), $value->getUid());
         }
         $owner = $value;
     }
     return [$value, $owner];
 }
开发者ID:mickaelsteinberg,项目名称:BackBee,代码行数:24,代码来源:IndexationListener.php

示例9: testFindStartableJobDetachesNonStartableJobs

 public function testFindStartableJobDetachesNonStartableJobs()
 {
     $a = new Job('a');
     $b = new Job('b');
     $a->addDependency($b);
     $this->em->persist($a);
     $this->em->persist($b);
     $this->em->flush();
     $this->assertTrue($this->em->contains($a));
     $this->assertTrue($this->em->contains($b));
     $excludedIds = array();
     $startableJob = $this->repo->findStartableJob($excludedIds);
     $this->assertNotNull($startableJob);
     $this->assertEquals($b->getId(), $startableJob->getId());
     $this->assertEquals(array($a->getId()), $excludedIds);
     $this->assertFalse($this->em->contains($a));
     $this->assertTrue($this->em->contains($b));
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:18,代码来源:JobRepositoryTest.php

示例10: contains

 /**
  * Determines whether an entity instance is managed in this EntityManager.
  *
  * @param object $entity
  * @return boolean TRUE if this EntityManager currently manages the given entity, FALSE otherwise.
  * @static 
  */
 public static function contains($entity)
 {
     return \Doctrine\ORM\EntityManager::contains($entity);
 }
开发者ID:kodorider,项目名称:renta,代码行数:11,代码来源:_ide_helper.php

示例11: contains

 /**
  * {@inheritdoc}
  */
 public function contains($entity)
 {
     return $this->wrapped->contains($entity);
 }
开发者ID:lstrojny,项目名称:doctrine-fun,代码行数:7,代码来源:EntityManagerDecorator.php


注:本文中的Doctrine\ORM\EntityManager::contains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。