Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
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
 * 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: sfValidatorI18nChoiceCountry.class.php 23940 2009-11-14 17:58:19Z fabien $
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
}