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


PHP EntityManager::initializeObject方法代码示例

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


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

示例1: is_uploaded

 /**
  * Checks if file is uploaded.
  *
  * @param mixed  $object
  * @param string $field
  *
  * @return bool|string
  */
 public function is_uploaded($object, $field)
 {
     if ($object === null) {
         return false;
     }
     try {
         $this->em->initializeObject($object);
         return $this->uploader->asset($object, $field);
     } catch (InvalidArgumentException $e) {
         return false;
     }
 }
开发者ID:rodgermd,项目名称:RodgerSfTools,代码行数:20,代码来源:ImagesManager.php

示例2: loadAndMergeEntity

 /**
  * @param \Scribe\Doctrine\ORM\Mapping\Entity|mixed $entity
  * @param mixed                                     $index
  *
  * @throws \Exception
  *
  * @return $this
  */
 protected function loadAndMergeEntity($index, $entity)
 {
     try {
         $entityMetadata = $this->getClassMetadata($this->getEntityFQCN());
         $this->identLog[] = $identity = $entityMetadata->getIdentifierValues($entity);
         if (count($identity) > 0) {
             $identity = [key($identity) => current($identity)];
         } elseif (!$entity->hasIdentity()) {
             OutBuffer::stat('+y/b-preload +y/i-[warns]+w/- import could not begin for "%s:%d"', basename($this->metadata->getName()), $index);
             OutBuffer::stat('+y/b-preload +y/i-[warns]+w/- import strategy "merge" unavailable due to failed identifier map resolution');
         }
         $repository = $this->manager->getRepository($this->getEntityFQCN());
         $entitySearched = $repository->findOneBy($identity);
         $this->manager->initializeObject($entitySearched);
         if ($entitySearched && !$entity->isEqualTo($entitySearched)) {
             $mapper = new HydratorManager(new HydratorMapping(true));
             $entity = $mapper->getMappedObject($entity, $entitySearched);
             $this->manager->remove($entitySearched);
             $this->manager->merge($entity);
             $this->manager->persist($entity);
             $this->manager->flush();
             $this->manager->clear();
             ++$this->countUpdate;
             return $this;
         } elseif ($entitySearched && $entity->isEqualTo($entitySearched)) {
             $entity = $entitySearched;
             ++$this->countSkip;
             return $this;
         }
         $this->loadAndPersistEntity($entity);
     } catch (\Exception $e) {
         throw $e;
     }
     return $this;
 }
开发者ID:scr-be,项目名称:arthur-doctrine-fixtures-bundle,代码行数:43,代码来源:AbstractFixture.php

示例3: validate

 /**
  * {@inheritdoc}
  */
 public function validate($entity, Constraint $constraint)
 {
     $parent = $entity->getParent();
     $this->entity = $entity;
     $this->parent = $parent;
     if ($parent) {
         $criticalError = false;
         try {
             $this->entityManager->initializeObject($parent);
         } catch (EntityNotFoundException $exception) {
             $this->addViolationAt($parent->getPrimaryKey(), $this->entity->getPrimaryKey(), null, 'Parent #%s of object #%s does not exist');
             $criticalError = true;
         }
         if ($criticalError === false) {
             $this->validateParent($entity, $parent);
         }
     }
 }
开发者ID:RuslanZavacky,项目名称:EcentriaRestBundle,代码行数:21,代码来源:CircularReferenceValidator.php

示例4: validate

 /**
  * {@inheritdoc}
  */
 public function validate($entity, Constraint $constraint)
 {
     if (!$constraint instanceof UniqueEntity) {
         throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\\UniqueEntity');
     }
     $criticalError = false;
     $class = $this->entityManager->getClassMetadata(get_class($entity));
     foreach ($constraint->fields as $fieldName) {
         $object = $class->reflFields[$fieldName]->getValue($entity);
         try {
             $this->entityManager->initializeObject($object);
         } catch (EntityNotFoundException $exception) {
             $this->context->addViolationAt($fieldName, $fieldName . ' does not exist');
             $criticalError = true;
         }
     }
     if ($criticalError === false) {
         parent::validate($entity, $constraint);
     }
 }
开发者ID:RuslanZavacky,项目名称:EcentriaRestBundle,代码行数:23,代码来源:UniqueEntityValidator.php

示例5: initializeObject

 /**
  * {@inheritDoc}
  *
  * @static 
  */
 public static function initializeObject($obj)
 {
     return \Doctrine\ORM\EntityManager::initializeObject($obj);
 }
开发者ID:kodorider,项目名称:renta,代码行数:9,代码来源:_ide_helper.php

示例6: validate

 /**
  * (StartDate1 <= EndDate2) and (StartDate2 <= EndDate1)
  * 
  * @param object $entity
  * @param \Symfony\Component\Validator\Constraint $constraint
  */
 public function validate($entity, Constraint $constraint)
 {
     if (!$constraint instanceof DateTimeIntersect) {
         throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\\DateTimeIntersect');
     }
     $class = $this->em->getClassMetadata(get_class($entity));
     /*@var $class \Doctrine\Common\Persistence\Mapping\ClassMetadata*/
     $errorPath = $this->getErrorPaths($constraint);
     foreach ($errorPath as $fieldName) {
         if (!$class->hasField($fieldName) && !is_null($fieldName)) {
             throw new ConstraintDefinitionException(sprintf("The field '%s' is not mapped by Doctrine.", $fieldName));
         }
     }
     $fields = $this->getFields($constraint);
     switch (false) {
         case $class->hasField($constraint->startDateField):
             throw new ConstraintDefinitionException(sprintf('There isn`t field %s in entity %s', $constraint->startDateField, get_class($entity)));
         case $class->hasField($constraint->endDateField):
             throw new ConstraintDefinitionException(sprintf('There isn`t field %s in entity %s', $constraint->endDateField, get_class($entity)));
     }
     $startDate = $class->getFieldValue($entity, $constraint->startDateField);
     $endDate = $class->getFieldValue($entity, $constraint->endDateField);
     if (null === $startDate || '' === $startDate || null === $endDate || '' === $endDate) {
         return;
     }
     if (!$startDate instanceof \DateTime) {
         throw new UnexpectedTypeException($entity->getStartDate(), '\\DateTime');
     }
     if (!$startDate instanceof \DateTime) {
         throw new UnexpectedTypeException($entity->getStartDate(), '\\DateTime');
     }
     if (!$endDate instanceof \DateTime) {
         throw new UnexpectedTypeException($endDate, '\\DateTime');
     }
     $criteria = array();
     foreach ($fields as $fieldName) {
         if (!$class->hasField($fieldName) && !$class->hasAssociation($fieldName)) {
             throw new ConstraintDefinitionException(sprintf("The field '%s' is not mapped by Doctrine.", $fieldName));
         }
         $criteria[$fieldName] = $class->reflFields[$fieldName]->getValue($entity);
         if (!is_null($criteria[$fieldName]) && $class->hasAssociation($fieldName)) {
             $this->em->initializeObject($criteria[$fieldName]);
             $relatedClass = $this->em->getClassMetadata($class->getAssociationTargetClass($fieldName));
             $relatedId = $relatedClass->getIdentifierValues($criteria[$fieldName]);
             if (count($relatedId) > 1) {
                 throw new ConstraintDefinitionException("Associated entities are not allowed to have more than one identifier");
             }
             $criteria[$fieldName] = array_pop($relatedId);
         }
     }
     $queryBuilder = $this->em->getRepository(get_class($entity))->createQueryBuilder('dti')->where("dti.{$constraint->startDateField} <= :startDate AND dti.{$constraint->endDateField} >= :startDate")->orWhere("dti.{$constraint->startDateField} <= :endDate AND dti.{$constraint->endDateField} >= :endDate")->setParameters(array('startDate' => $class->getFieldValue($entity, $constraint->startDateField), 'endDate' => $class->getFieldValue($entity, $constraint->endDateField)));
     foreach ($criteria as $field => $value) {
         $queryBuilder->andWhere("dti.{$field} = :{$field}")->setParameter($field, $value);
     }
     $result = $queryBuilder->getQuery()->getResult();
     $result instanceof \Iterator ? $result->rewind() : reset($result);
     if (count($result) === 0 || count($result) === 1 && $entity === ($result instanceof \Iterator ? $result->current() : current($result))) {
         return;
     }
     $names = array();
     foreach ($result as $range) {
         if ($range !== $entity) {
             $names[] = "{$range->getStartDate()->format('Y-m-d')} - {$range->getEndDate()->format('Y-m-d')}";
         }
     }
     if (!empty($names)) {
         foreach ($errorPath as $errorPathItem) {
             $this->buildViolation(sprintf($constraint->message))->setParameter('{{ intersects }}', implode(', ', $names))->atPath($errorPathItem)->setInvalidValue($criteria[$fields[0]])->addViolation();
         }
     }
 }
开发者ID:bestmodules,项目名称:daterange-validator-bundle,代码行数:77,代码来源:DateTimeIntersectValidator.php

示例7: initializeObject

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


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