1
0
mirror of synced 2024-12-05 03:06:05 +03:00

#1240 DDC-3479 - Using a static proxy constructor rather than the default constructor

This commit is contained in:
Marco Pivetta 2015-01-13 02:51:47 +01:00
parent 66c556fbfd
commit fc72b41953
3 changed files with 13 additions and 7 deletions

View File

@ -28,13 +28,16 @@ namespace Doctrine\ORM;
class EntityNotFoundException extends ORMException
{
/**
* Constructor.
* Static constructor.
*
* @param string $className
* @param string[] $id
*
* @return self
*/
public function __construct($className, array $id = array())
public static function fromClassNameAndIdentifier($className, array $id)
{
$ids = array();
foreach ($id as $key => $value) {
@ -42,7 +45,7 @@ class EntityNotFoundException extends ORMException
}
parent::__construct(
return new self(
'Entity of type \'' . $className . '\'' . ($ids ? ' for IDs ' . implode(', ', $ids) : '') . ' was not found'
);
}

View File

@ -154,7 +154,7 @@ class ProxyFactory extends AbstractProxyFactory
$proxy->__setCloner($cloner);
$proxy->__setInitialized(false);
throw new EntityNotFoundException(
throw EntityNotFoundException::fromClassNameAndIdentifier(
$classMetadata->getName(),
$identifierFlattener->flattenIdentifier($classMetadata, $identifier)
);
@ -190,7 +190,7 @@ class ProxyFactory extends AbstractProxyFactory
$proxy->__setCloner($cloner);
$proxy->__setInitialized(false);
throw new EntityNotFoundException(
throw EntityNotFoundException::fromClassNameAndIdentifier(
$classMetadata->getName(),
$identifierFlattener->flattenIdentifier($classMetadata, $identifier)
);
@ -225,7 +225,7 @@ class ProxyFactory extends AbstractProxyFactory
$original = $entityPersister->loadById($identifier);
if (null === $original) {
throw new EntityNotFoundException(
throw EntityNotFoundException::fromClassNameAndIdentifier(
$classMetadata->getName(),
$identifierFlattener->flattenIdentifier($classMetadata, $identifier)
);

View File

@ -1843,7 +1843,10 @@ class UnitOfWork implements PropertyChangedListener
// If the identifier is ASSIGNED, it is NEW, otherwise an error
// since the managed entity was not found.
if ( ! $class->isIdentifierNatural()) {
throw new EntityNotFoundException($class->getName(), $this->identifierFlattener->flattenIdentifier($class, $id));
throw EntityNotFoundException::fromClassNameAndIdentifier(
$class->getName(),
$this->identifierFlattener->flattenIdentifier($class, $id)
);
}
$managedCopy = $this->newInstance($class);