Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bridge\Doctrine\Validator; | ||
|
||
use Symfony\Bridge\Doctrine\RegistryInterface; | ||
use Symfony\Component\Validator\ObjectInitializerInterface; | ||
use Doctrine\ORM\Proxy\Proxy; | ||
|
||
/** | ||
* Automatically loads proxy object before validation. | ||
* | ||
* @author Fabien Potencier <fabien@symfony.com> | ||
*/ | ||
class EntityInitializer implements ObjectInitializerInterface | ||
{ | ||
protected $registry; | ||
|
||
public function __construct(RegistryInterface $registry) | ||
{ | ||
$this->registry = $registry; | ||
} | ||
|
||
public function initialize($object) | ||
{ | ||
if ($object instanceof Proxy) { | ||
$this->registry->getEntityManagerForObject($object)->getUnitOfWork()->initializeObject($object); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
fabpot
Author
Member
|
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
|
||
class AddValidatorInitializersPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
if (!$container->hasDefinition('validator')) { | ||
return; | ||
} | ||
|
||
$initializers = array(); | ||
foreach ($container->findTaggedServiceIds('validator.initializer') as $id => $attributes) { | ||
$initializers[] = new Reference($id); | ||
} | ||
|
||
$container->getDefinition('validator')->replaceArgument(2, $initializers); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Validator; | ||
|
||
/** | ||
* Interface for object initializers. | ||
* | ||
* Concrete implementations of this interface are used by the GraphWalker | ||
* to initialize objects just before validating them/ | ||
* | ||
* @author Fabien Potencier <fabien@symfony.com> | ||
*/ | ||
interface ObjectInitializerInterface | ||
{ | ||
/** | ||
* Initializes an object just before validation. | ||
* | ||
* @param object $object The object to validate | ||
*/ | ||
function initialize($object); | ||
} |
2 comments
on commit 0824736
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit introduces an issue for me. Well, i'm not sure if it's an issue or an undocumented BC break, but since these changes i get the following error on a form process which was working just before this push :
Warning: strpos() expects parameter 1 to be string, object given in F:\PHPServer\Zend\Apache2\htdocs\mval\vendor\doctrine\lib\Doctrine\ORM\Mapping\Driver\DriverChain.php line 113
Here is the end of the stack trace : http://awesomescreenshot.com/0d6gb4035
The isTransient() method is called (by the Registry) with an object instead of a string as parameter.
Not sure of what i need to do to fix this so i prefer letting you doing it to avoid unwanted issues :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fixed by #1600 which is not merged yet.
The method of the registry can return
null
if the entity manager is not found. So you should test this case here.