Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 62 lines (52 sloc) 1.862 kB
35c37c4 @webmozart [Validator] Implemented Execute constraint
webmozart authored
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
fec10a4 @fabpot replaced symfony-project.org by symfony.com
fabpot authored
6 * (c) Fabien Potencier <fabien@symfony.com>
35c37c4 @webmozart [Validator] Implemented Execute constraint
webmozart authored
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\Validator\Constraints;
13
14 use Symfony\Component\Validator\Constraint;
15 use Symfony\Component\Validator\ConstraintValidator;
16 use Symfony\Component\Validator\Exception\UnexpectedTypeException;
150aa5d @lsmith77 some fixes by just "blindly" trying to make phpStorm code analysis ha…
lsmith77 authored
17 use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
35c37c4 @webmozart [Validator] Implemented Execute constraint
webmozart authored
18
19 /**
64bc211 @webmozart [Validator] Renamed Execute constraint to Callback
webmozart authored
20 * Validator for Callback constraint
35c37c4 @webmozart [Validator] Implemented Execute constraint
webmozart authored
21 *
529a58d @webmozart [Validator] Removed return value from ConstraintValidatorInterface::i…
webmozart authored
22 * @author Bernhard Schussek <bschussek@gmail.com>
be4f2a0 @fabpot [Validator] tagged the public @api
fabpot authored
23 *
24 * @api
35c37c4 @webmozart [Validator] Implemented Execute constraint
webmozart authored
25 */
64bc211 @webmozart [Validator] Renamed Execute constraint to Callback
webmozart authored
26 class CallbackValidator extends ConstraintValidator
35c37c4 @webmozart [Validator] Implemented Execute constraint
webmozart authored
27 {
be4f2a0 @fabpot [Validator] tagged the public @api
fabpot authored
28 /**
9bde527 @danielholmes [Validator] Added inheritDoc phpdoc for validate methods
danielholmes authored
29 * {@inheritDoc}
be4f2a0 @fabpot [Validator] tagged the public @api
fabpot authored
30 */
734609c @webmozart [Validator] Renamed ConstraintValidatorInterface::isValid() to valida…
webmozart authored
31 public function validate($object, Constraint $constraint)
35c37c4 @webmozart [Validator] Implemented Execute constraint
webmozart authored
32 {
33 if (null === $object) {
529a58d @webmozart [Validator] Removed return value from ConstraintValidatorInterface::i…
webmozart authored
34 return;
35c37c4 @webmozart [Validator] Implemented Execute constraint
webmozart authored
35 }
36
2a730bf @webmozart [Validator] Added support for static callbacks to Callback constraint
webmozart authored
37 // has to be an array so that we can differentiate between callables
38 // and method names
39 if (!is_array($constraint->methods)) {
40 throw new UnexpectedTypeException($constraint->methods, 'array');
41 }
42
43 $methods = $constraint->methods;
35c37c4 @webmozart [Validator] Implemented Execute constraint
webmozart authored
44
45 foreach ($methods as $method) {
ebbede3 @johnwards [Validator] Adding support for Closure in CallbackValidator
johnwards authored
46 if (is_array($method) || $method instanceof \Closure) {
2a730bf @webmozart [Validator] Added support for static callbacks to Callback constraint
webmozart authored
47 if (!is_callable($method)) {
48 throw new ConstraintDefinitionException(sprintf('"%s::%s" targeted by Callback constraint is not a valid callable', $method[0], $method[1]));
49 }
35c37c4 @webmozart [Validator] Implemented Execute constraint
webmozart authored
50
529a58d @webmozart [Validator] Removed return value from ConstraintValidatorInterface::i…
webmozart authored
51 call_user_func($method, $object, $this->context);
2a730bf @webmozart [Validator] Added support for static callbacks to Callback constraint
webmozart authored
52 } else {
53 if (!method_exists($object, $method)) {
54 throw new ConstraintDefinitionException(sprintf('Method "%s" targeted by Callback constraint does not exist', $method));
55 }
56
529a58d @webmozart [Validator] Removed return value from ConstraintValidatorInterface::i…
webmozart authored
57 $object->$method($this->context);
2a730bf @webmozart [Validator] Added support for static callbacks to Callback constraint
webmozart authored
58 }
35c37c4 @webmozart [Validator] Implemented Execute constraint
webmozart authored
59 }
60 }
150aa5d @lsmith77 some fixes by just "blindly" trying to make phpStorm code analysis ha…
lsmith77 authored
61 }
Something went wrong with that request. Please try again.