2011-02-03 09:40:53 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2011-02-03 09:40:53 +00:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Symfony\Component\Validator\Constraints;
|
|
|
|
|
2011-05-19 08:34:54 +01:00
|
|
|
use Symfony\Component\Validator\Constraint;
|
|
|
|
|
2011-07-20 09:37:57 +01:00
|
|
|
/**
|
|
|
|
* @Annotation
|
2014-04-23 11:57:22 +01:00
|
|
|
* @Target("CLASS")
|
2011-07-20 09:37:57 +01:00
|
|
|
*
|
2013-04-17 17:02:12 +01:00
|
|
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
|
|
|
*
|
2011-07-20 09:37:57 +01:00
|
|
|
* @api
|
|
|
|
*/
|
2011-05-19 08:34:54 +01:00
|
|
|
class Callback extends Constraint
|
2011-02-03 09:40:53 +00:00
|
|
|
{
|
2013-09-26 10:03:13 +01:00
|
|
|
/**
|
|
|
|
* @var string|callable
|
|
|
|
*
|
|
|
|
* @since 2.4
|
|
|
|
*/
|
|
|
|
public $callback;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*
|
|
|
|
* @deprecated Deprecated since version 2.4, to be removed in Symfony 3.0.
|
|
|
|
*/
|
2011-02-03 09:40:53 +00:00
|
|
|
public $methods;
|
|
|
|
|
|
|
|
/**
|
2013-09-26 10:03:13 +01:00
|
|
|
* {@inheritdoc}
|
2011-02-03 09:40:53 +00:00
|
|
|
*/
|
2013-09-26 10:03:13 +01:00
|
|
|
public function __construct($options = null)
|
2011-02-03 09:40:53 +00:00
|
|
|
{
|
2013-09-26 10:03:13 +01:00
|
|
|
// Invocation through annotations with an array parameter only
|
|
|
|
if (is_array($options) && 1 === count($options) && isset($options['value'])) {
|
|
|
|
$options = $options['value'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_array($options) && !isset($options['callback']) && !isset($options['methods']) && !isset($options['groups'])) {
|
|
|
|
if (is_callable($options)) {
|
|
|
|
$options = array('callback' => $options);
|
|
|
|
} else {
|
|
|
|
// BC with Symfony < 2.4
|
|
|
|
$options = array('methods' => $options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
parent::__construct($options);
|
2011-02-03 09:40:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-26 10:03:13 +01:00
|
|
|
* {@inheritdoc}
|
2011-02-03 09:40:53 +00:00
|
|
|
*/
|
2011-03-30 22:18:15 +01:00
|
|
|
public function getDefaultOption()
|
2011-02-03 09:40:53 +00:00
|
|
|
{
|
2013-09-26 10:03:13 +01:00
|
|
|
return 'callback';
|
2011-02-03 09:40:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-26 10:03:13 +01:00
|
|
|
* {@inheritdoc}
|
2011-02-03 09:40:53 +00:00
|
|
|
*/
|
2011-03-30 22:18:15 +01:00
|
|
|
public function getTargets()
|
2011-02-03 09:40:53 +00:00
|
|
|
{
|
|
|
|
return self::CLASS_CONSTRAINT;
|
|
|
|
}
|
|
|
|
}
|