Development

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

You must first sign up to be able to contribute.

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

Revision 11700, 1.6 kB (checked in by fabien, 6 years ago)

[1.1, 1.2] changed internal classes to always use the sfCultureInfo singleton

  • 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     // culture is deprecated
38     $this->addOption('culture');
39     $this->addOption('countries');
40
41     // populate choices with all countries
42     $countries = array_keys(sfCultureInfo::getInstance()->getCountries());
43
44     // restrict countries to a sub-set
45     if (isset($options['countries']))
46     {
47       if ($problems = array_diff($options['countries'], $countries))
48       {
49         throw new InvalidArgumentException(sprintf('The following countries do not exist: %s.', implode(', ', $problems)));
50       }
51
52       $countries = $options['countries'];
53     }
54
55     sort($countries);
56
57     $this->setOption('choices', $countries);
58   }
59 }
60
Note: See TracBrowser for help on using the browser.