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 16:17:21 +01:00
|
|
|
* @Target({"CLASS", "PROPERTY", "METHOD", "ANNOTATION"})
|
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
|
|
|
*/
|
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;
|
|
|
|
|
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
|
|
|
*/
|
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'];
|
|
|
|
}
|
|
|
|
|
2015-09-30 14:14:41 +01:00
|
|
|
if (is_array($options) && !isset($options['callback']) && !isset($options['groups'])) {
|
2015-01-09 06:49:26 +00:00
|
|
|
if (is_callable($options) || !$options) {
|
2013-09-26 10:03:13 +01:00
|
|
|
$options = array('callback' => $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
|
|
|
{
|
2014-02-12 11:38:50 +00:00
|
|
|
return array(self::CLASS_CONSTRAINT, self::PROPERTY_CONSTRAINT);
|
2011-02-03 09:40:53 +00:00
|
|
|
}
|
|
|
|
}
|