Drupal investigation

Count.php 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. use Symfony\Component\Validator\Exception\MissingOptionsException;
  13. /**
  14. * @Annotation
  15. * @Target({"PROPERTY", "METHOD", "ANNOTATION"})
  16. *
  17. * @author Bernhard Schussek <bschussek@gmail.com>
  18. */
  19. class Count extends Constraint
  20. {
  21. const TOO_FEW_ERROR = 'bef8e338-6ae5-4caf-b8e2-50e7b0579e69';
  22. const TOO_MANY_ERROR = '756b1212-697c-468d-a9ad-50dd783bb169';
  23. protected static $errorNames = array(
  24. self::TOO_FEW_ERROR => 'TOO_FEW_ERROR',
  25. self::TOO_MANY_ERROR => 'TOO_MANY_ERROR',
  26. );
  27. public $minMessage = 'This collection should contain {{ limit }} element or more.|This collection should contain {{ limit }} elements or more.';
  28. public $maxMessage = 'This collection should contain {{ limit }} element or less.|This collection should contain {{ limit }} elements or less.';
  29. public $exactMessage = 'This collection should contain exactly {{ limit }} element.|This collection should contain exactly {{ limit }} elements.';
  30. public $min;
  31. public $max;
  32. public function __construct($options = null)
  33. {
  34. if (null !== $options && !is_array($options)) {
  35. $options = array(
  36. 'min' => $options,
  37. 'max' => $options,
  38. );
  39. }
  40. parent::__construct($options);
  41. if (null === $this->min && null === $this->max) {
  42. throw new MissingOptionsException(sprintf('Either option "min" or "max" must be given for constraint %s', __CLASS__), array('min', 'max'));
  43. }
  44. }
  45. }