Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # symfony validator service classes
- use Doctrine\ORM\Mapping as ORM;
- use Symfony\Component\Validator\Validator;
- use Symfony\Component\Validator\ValidatorFactory;
- /**
- * Base class which contains commonly used funcitons, as of Doctrine2 it does not need to extend any Doctrine specific class
- *
- * @ORM\MappedSuperclass
- * @ORM\HasLifecycleCallbacks
- *
- */
- class BaseRecord {
- /**
- * Hook to validate entities before they are persisted to the database, will not throw exceptions
- * but will update the error stack as Doctrine1 did
- *
- * @return bool
- *
- * @ORM\PrePersist
- * @ORM\PreUpdate
- */
- public function validate(){
- $factory = ValidatorFactory::buildDefault();
- $validator = $factory->getValidator();
- $violations = $validator->validate($this);
- debugMessage($violations);
- if ($violations->count() > 0) {
- // add the violation messages to the errors array, they will be translated
- foreach ($violations as $violation) {
- $this->errorstack[] = $violaton->getMessage();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement