本文整理汇总了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;
}
}
示例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;
}
示例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);
}
}
}
示例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);
}
}
示例5: initializeObject
/**
* {@inheritDoc}
*
* @static
*/
public static function initializeObject($obj)
{
return \Doctrine\ORM\EntityManager::initializeObject($obj);
}
示例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();
}
}
}
示例7: initializeObject
/**
* {@inheritdoc}
*/
public function initializeObject($obj)
{
return $this->wrapped->initializeObject($obj);
}