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
*/
public $callback ;
/**
* @ var array
*
2014-12-29 23:26:56 +00:00
* @ deprecated since version 2.4 , to be removed in 3.0 .
2013-09-26 10:03:13 +01:00
*/
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' ];
}
2015-01-09 06:49:26 +00:00
if ( is_array ( $options ) && isset ( $options [ 'methods' ])) {
2015-06-07 07:33:05 +01:00
@ 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 );
2015-01-09 06:49:26 +00:00
}
2016-03-24 14:49:51 +00:00
if ( is_array ( $options ) && ! isset ( $options [ 'callback' ]) && ! isset ( $options [ 'methods' ]) && ! isset ( $options [ 'groups' ]) && ! isset ( $options [ 'payload' ])) {
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 );
} else {
2015-01-09 06:49:26 +00:00
// @deprecated, to be removed in 3.0
2013-09-26 10:03:13 +01:00
$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
{
2014-02-12 11:38:50 +00:00
return array ( self :: CLASS_CONSTRAINT , self :: PROPERTY_CONSTRAINT );
2011-02-03 09:40:53 +00:00
}
}