Created
February 28, 2012 17:00
-
-
Save frosas/1933660 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
entity_validator: | |
class: Vendor\AppBundle\Entity\Validator | |
arguments: [@validator] | |
tags: | |
- { name: doctrine.event_listener, event: prePersist } | |
- { name: doctrine.event_listener, event: preUpdate } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Vendor\AppBundle\Entity; | |
use Symfony\Component\Validator\Validator as SymfonyValidator; | |
use Doctrine\ORM\Event\LifecycleEventArgs; | |
class Validator { | |
private $validator; | |
function __construct(SymfonyValidator $validator) { | |
$this->validator = $validator; | |
} | |
function __call($method, $args) { | |
$entity = reset($args)->getEntity(); | |
$this->validator->validate($entity); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment