Skip to content

Instantly share code, notes, and snippets.

@frosas
Created February 28, 2012 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frosas/1933660 to your computer and use it in GitHub Desktop.
Save frosas/1933660 to your computer and use it in GitHub Desktop.
services:
entity_validator:
class: Vendor\AppBundle\Entity\Validator
arguments: [@validator]
tags:
- { name: doctrine.event_listener, event: prePersist }
- { name: doctrine.event_listener, event: preUpdate }
<?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