vendor/symfony/validator/Constraints/Callback.php line 22

Open in your IDE?
  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({"CLASS", "PROPERTY", "METHOD", "ANNOTATION"})
  15.  *
  16.  * @author Bernhard Schussek <bschussek@gmail.com>
  17.  */
  18. class Callback extends Constraint
  19. {
  20.     /**
  21.      * @var string|callable
  22.      */
  23.     public $callback;
  24.     /**
  25.      * {@inheritdoc}
  26.      */
  27.     public function __construct($options null)
  28.     {
  29.         // Invocation through annotations with an array parameter only
  30.         if (\is_array($options) && === \count($options) && isset($options['value'])) {
  31.             $options $options['value'];
  32.         }
  33.         if (\is_array($options) && !isset($options['callback']) && !isset($options['groups']) && !isset($options['payload'])) {
  34.             $options = ['callback' => $options];
  35.         }
  36.         parent::__construct($options);
  37.     }
  38.     /**
  39.      * {@inheritdoc}
  40.      */
  41.     public function getDefaultOption()
  42.     {
  43.         return 'callback';
  44.     }
  45.     /**
  46.      * {@inheritdoc}
  47.      */
  48.     public function getTargets()
  49.     {
  50.         return [self::CLASS_CONSTRAINTself::PROPERTY_CONSTRAINT];
  51.     }
  52. }