Drupal investigation

Callback.php 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. * @var array
  26. *
  27. * @deprecated since version 2.4, to be removed in 3.0.
  28. */
  29. public $methods;
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function __construct($options = null)
  34. {
  35. // Invocation through annotations with an array parameter only
  36. if (is_array($options) && 1 === count($options) && isset($options['value'])) {
  37. $options = $options['value'];
  38. }
  39. if (is_array($options) && isset($options['methods'])) {
  40. @trigger_error('The "methods" option of the '.__CLASS__.' class is deprecated since version 2.4 and will be removed in 3.0. Use the "callback" option instead.', E_USER_DEPRECATED);
  41. }
  42. if (is_array($options) && !isset($options['callback']) && !isset($options['methods']) && !isset($options['groups']) && !isset($options['payload'])) {
  43. if (is_callable($options) || !$options) {
  44. $options = array('callback' => $options);
  45. } else {
  46. // @deprecated, to be removed in 3.0
  47. $options = array('methods' => $options);
  48. }
  49. }
  50. parent::__construct($options);
  51. }
  52. /**
  53. * {@inheritdoc}
  54. */
  55. public function getDefaultOption()
  56. {
  57. return 'callback';
  58. }
  59. /**
  60. * {@inheritdoc}
  61. */
  62. public function getTargets()
  63. {
  64. return array(self::CLASS_CONSTRAINT, self::PROPERTY_CONSTRAINT);
  65. }
  66. }