Development

/branches/1.3/lib/validator/i18n/sfValidatorI18nChoiceLanguage.class.php

You must first sign up to be able to contribute.

root/branches/1.3/lib/validator/i18n/sfValidatorI18nChoiceLanguage.class.php

Revision 23734, 1.5 kB (checked in by FabianLange, 5 years ago)

[1.3] removed incorrect reference to ISO-639-1 (refs #7022)

  • 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  * sfValidatorI18nChoiceLanguage validates than the value is a valid language.
13  *
14  * @package    symfony
15  * @subpackage validator
16  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17  * @version    SVN: $Id$
18  */
19 class sfValidatorI18nChoiceLanguage extends sfValidatorChoice
20 {
21   /**
22    * Configures the current validator.
23    *
24    * Available options:
25    *
26    *  * languages: An array of language codes to use
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('languages');
40
41     // populate choices with all languages
42     $languages = array_keys(sfCultureInfo::getInstance()->getLanguages());
43
44     // restrict languages to a sub-set
45     if (isset($options['languages']))
46     {
47       if ($problems = array_diff($options['languages'], $languages))
48       {
49         throw new InvalidArgumentException(sprintf('The following languages do not exist: %s.', implode(', ', $problems)));
50       }
51
52       $languages = $options['languages'];
53     }
54
55     $this->setOption('choices', $languages);
56   }
57 }
58
Note: See TracBrowser for help on using the browser.