2010-06-24 09:40:05 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2011-01-15 13:29:43 +00:00
|
|
|
* This file is part of the Symfony package.
|
2010-10-02 11:42:31 +01:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2010-06-24 09:40:05 +01:00
|
|
|
*
|
2011-01-15 13:29:43 +00:00
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
2010-06-24 09:40:05 +01:00
|
|
|
*/
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
namespace Symfony\Component\Validator\Constraints;
|
|
|
|
|
2012-12-29 09:43:12 +00:00
|
|
|
use Symfony\Component\Validator\Constraint;
|
|
|
|
|
2011-07-20 09:37:57 +01:00
|
|
|
/**
|
|
|
|
* @Annotation
|
2014-04-23 11:57:22 +01:00
|
|
|
* @Target({"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
|
|
|
* @api
|
|
|
|
*/
|
2012-12-29 09:43:12 +00:00
|
|
|
class Choice extends Constraint
|
2010-06-24 09:40:05 +01:00
|
|
|
{
|
2014-09-24 11:08:18 +01:00
|
|
|
const NO_SUCH_CHOICE_ERROR = 1;
|
|
|
|
const TOO_FEW_ERROR = 2;
|
|
|
|
const TOO_MANY_ERROR = 3;
|
|
|
|
|
|
|
|
protected static $errorNames = array(
|
|
|
|
self::NO_SUCH_CHOICE_ERROR => 'NO_SUCH_CHOICE_ERROR',
|
|
|
|
self::TOO_FEW_ERROR => 'TOO_FEW_ERROR',
|
|
|
|
self::TOO_MANY_ERROR => 'TOO_MANY_ERROR',
|
|
|
|
);
|
|
|
|
|
2012-12-29 09:43:12 +00:00
|
|
|
public $choices;
|
|
|
|
public $callback;
|
|
|
|
public $multiple = false;
|
|
|
|
public $strict = false;
|
2014-06-17 11:31:26 +01:00
|
|
|
public $min;
|
|
|
|
public $max;
|
2012-12-29 09:43:12 +00:00
|
|
|
public $message = 'The value you selected is not a valid choice.';
|
|
|
|
public $multipleMessage = 'One or more of the given values is invalid.';
|
2012-12-03 15:49:07 +00:00
|
|
|
public $minMessage = 'You must select at least {{ limit }} choice.|You must select at least {{ limit }} choices.';
|
|
|
|
public $maxMessage = 'You must select at most {{ limit }} choice.|You must select at most {{ limit }} choices.';
|
2012-12-29 09:43:12 +00:00
|
|
|
|
|
|
|
/**
|
2014-04-15 06:57:34 +01:00
|
|
|
* {@inheritdoc}
|
2012-12-29 09:43:12 +00:00
|
|
|
*/
|
|
|
|
public function getDefaultOption()
|
2010-06-24 10:24:08 +01:00
|
|
|
{
|
2012-12-29 09:43:12 +00:00
|
|
|
return 'choices';
|
2010-06-24 10:24:08 +01:00
|
|
|
}
|
2010-06-24 09:40:05 +01:00
|
|
|
}
|