Unique.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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\Component\Validator\Constraints;
  11. use Symfony\Component\Validator\Constraint;
  12. /**
  13. * @Annotation
  14. * @Target({"PROPERTY", "METHOD", "ANNOTATION"})
  15. *
  16. * @author Yevgeniy Zholkevskiy <zhenya.zholkevskiy@gmail.com>
  17. */
  18. #[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
  19. class Unique extends Constraint
  20. {
  21. public const IS_NOT_UNIQUE = '7911c98d-b845-4da0-94b7-a8dac36bc55a';
  22. protected static $errorNames = [
  23. self::IS_NOT_UNIQUE => 'IS_NOT_UNIQUE',
  24. ];
  25. public $message = 'This collection should contain only unique elements.';
  26. public function __construct(
  27. array $options = null,
  28. string $message = null,
  29. array $groups = null,
  30. $payload = null
  31. ) {
  32. parent::__construct($options, $groups, $payload);
  33. $this->message = $message ?? $this->message;
  34. }
  35. }