Merge remote branch 'vicb/form-tz-choice-list'

* vicb/form-tz-choice-list:
  [Form] Make TimezoneChoiceList implement ChoiceListInterface rather than extend ArrayChoiceList
This commit is contained in:
Fabien Potencier 2011-05-11 10:07:35 +02:00
commit 534cf8fce7

View File

@ -16,21 +16,16 @@ namespace Symfony\Component\Form\Extension\Core\ChoiceList;
* *
* @author Bernhard Schussek <bernhard.schussek@symfony.com> * @author Bernhard Schussek <bernhard.schussek@symfony.com>
*/ */
class TimezoneChoiceList extends ArrayChoiceList class TimezoneChoiceList implements ChoiceListInterface
{ {
/** /**
* Stores the available timezone choices * Stores the available timezone choices
* @var array * @var array
*/ */
protected static $timezones = array(); protected static $timezones;
public function __construct()
{
parent::__construct(array());
}
/** /**
* Loads the timezone choices * Returns the timezone choices.
* *
* The choices are generated from the ICU function * The choices are generated from the ICU function
* \DateTimeZone::listIdentifiers(). They are cached during a single request, * \DateTimeZone::listIdentifiers(). They are cached during a single request,
@ -39,11 +34,9 @@ class TimezoneChoiceList extends ArrayChoiceList
* *
* @return array The timezone choices * @return array The timezone choices
*/ */
protected function load() public function getChoices()
{ {
parent::load(); if (count(static::$timezones) == 0) {
if (count(self::$timezones) == 0) {
foreach (\DateTimeZone::listIdentifiers() as $timezone) { foreach (\DateTimeZone::listIdentifiers() as $timezone) {
$parts = explode('/', $timezone); $parts = explode('/', $timezone);
@ -58,14 +51,14 @@ class TimezoneChoiceList extends ArrayChoiceList
$name = $parts[0]; $name = $parts[0];
} }
if (!isset(self::$timezones[$region])) { if (!isset(static::$timezones[$region])) {
self::$timezones[$region] = array(); static::$timezones[$region] = array();
} }
self::$timezones[$region][$timezone] = str_replace('_', ' ', $name); static::$timezones[$region][$timezone] = str_replace('_', ' ', $name);
} }
} }
$this->choices = self::$timezones; return static::$timezones;
} }
} }