本文整理汇总了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;
}
示例2: onClear
/**
*
*/
public function onClear(\Doctrine\Common\EventArgs $args)
{
foreach ($this->array as $entity) {
if (!$this->entityManager->contains($entity)) {
$entity->free();
}
}
}
示例3: persistEntity
/**
* @param $entity
*/
private function persistEntity($entity)
{
if ($this->isEntity($entity)) {
if (!$this->em->contains($entity)) {
$this->em->persist($entity);
$this->persistAllAssociations($entity);
}
}
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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];
}
示例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));
}
示例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);
}
示例11: contains
/**
* {@inheritdoc}
*/
public function contains($entity)
{
return $this->wrapped->contains($entity);
}