UniqueEntity.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bridge\Doctrine\Validator\Constraints;
  11. use Symfony\Component\Validator\Constraint;
  12. /**
  13. * Constraint for the Unique Entity validator.
  14. *
  15. * @Annotation
  16. * @Target({"CLASS", "ANNOTATION"})
  17. *
  18. * @author Benjamin Eberlei <kontakt@beberlei.de>
  19. */
  20. class UniqueEntity extends Constraint
  21. {
  22. const NOT_UNIQUE_ERROR = '23bd9dbf-6b9b-41cd-a99e-4844bcf3077f';
  23. public $message = 'This value is already used.';
  24. public $service = 'doctrine.orm.validator.unique';
  25. public $em = null;
  26. public $repositoryMethod = 'findBy';
  27. public $fields = array();
  28. public $errorPath = null;
  29. public $ignoreNull = true;
  30. protected static $errorNames = array(
  31. self::NOT_UNIQUE_ERROR => 'NOT_UNIQUE_ERROR',
  32. );
  33. public function getRequiredOptions()
  34. {
  35. return array('fields');
  36. }
  37. /**
  38. * The validator must be defined as a service with this name.
  39. *
  40. * @return string
  41. */
  42. public function validatedBy()
  43. {
  44. return $this->service;
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function getTargets()
  50. {
  51. return self::CLASS_CONSTRAINT;
  52. }
  53. public function getDefaultOption()
  54. {
  55. return 'fields';
  56. }
  57. }