Callback.php 2.0 KB

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