Development

/branches/1.4/lib/validator/i18n/sfValidatorI18nChoiceCountry.class.php

You must first sign up to be able to contribute.

root/branches/1.4/lib/validator/i18n/sfValidatorI18nChoiceCountry.class.php

Revision 23940, 1.5 kB (checked in by fabien, 4 years ago)

[1.4] more deprecated stuff removed

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * sfValidatorI18nChoiceCountry validates than the value is a valid country.
13  *
14  * @package    symfony
15  * @subpackage validator
16  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17  * @version    SVN: $Id$
18  */
19 class sfValidatorI18nChoiceCountry extends sfValidatorChoice
20 {
21   /**
22    * Configures the current validator.
23    *
24    * Available options:
25    *
26    *  * countries: An array of country codes to use (ISO 3166)
27    *
28    * @param array $options   An array of options
29    * @param array $messages  An array of error messages
30    *
31    * @see sfValidatorChoice
32    */
33   protected function configure($options = array(), $messages = array())
34   {
35     parent::configure($options, $messages);
36
37     $this->addOption('countries');
38
39     // populate choices with all countries
40     $countries = array_keys(sfCultureInfo::getInstance()->getCountries());
41
42     // restrict countries to a sub-set
43     if (isset($options['countries']))
44     {
45       if ($problems = array_diff($options['countries'], $countries))
46       {
47         throw new InvalidArgumentException(sprintf('The following countries do not exist: %s.', implode(', ', $problems)));
48       }
49
50       $countries = $options['countries'];
51     }
52
53     $this->setOption('choices', $countries);
54   }
55 }
56
Note: See TracBrowser for help on using the browser.