| 1 |
lars |
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: sfValidatorI18nChoiceLanguage.class.php 23940 2009-11-14 17:58:19Z fabien $
|
|
|
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 |
$this->addOption('languages');
|
|
|
38 |
|
|
|
39 |
// populate choices with all languages
|
|
|
40 |
$languages = array_keys(sfCultureInfo::getInstance()->getLanguages());
|
|
|
41 |
|
|
|
42 |
// restrict languages to a sub-set
|
|
|
43 |
if (isset($options['languages']))
|
|
|
44 |
{
|
|
|
45 |
if ($problems = array_diff($options['languages'], $languages))
|
|
|
46 |
{
|
|
|
47 |
throw new InvalidArgumentException(sprintf('The following languages do not exist: %s.', implode(', ', $problems)));
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
$languages = $options['languages'];
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
$this->setOption('choices', $languages);
|
|
|
54 |
}
|
|
|
55 |
}
|