text pair. * * The text is displayed in a drop-down; the value is returned. * * If function timezones_value() exists, it is called to create the displayed * text. */ /** * Class extended_timezones. */ class extended_timezones { /** * @var array */ private $timezonesList = array(); /** * @var bool */ private $isEOF = false; // True if at last element of list. /** * @var bool */ private $bufferValid = false; /** * Constructor. */ public function __construct() { $this->timezonesList = systemTimeZones(); } /** * Call before using the 'next' format option, to ensure the array is * indexed from the beginning. */ public function pointerReset() { $this->isEOF = (false === reset($this->timezonesList)); $this->bufferValid = true; } /** * Return a formatted timezone value * * @param mixed $key * The key value to select. * @param string $formatSpec * Defines format of return value. * * @return mixed * (according to $formatSpec). * false - if no value available. * 'array' - a single-element array; key as passed, and value to match key * 'next' - as 'array', but ignores the passed $key and moves to next value. * 'default' - a string usable for display. */ public function getValue($key, $formatSpec = '') { if($formatSpec == 'next') { // Make sure buffer is defined. if(!$this->bufferValid) { $this->pointerReset(); } if($this->isEOF) { return false; } $key = key($this->timezonesList); $val = current($this->timezonesList); if(false === $val) { $this->isEOF = true; return false; } $this->isEOF = (false === next($this->timezonesList)); return array($key => $val); } $exists = isset($this->timezonesList[$key]); if(!$exists) { return false; } $val = $this->timezonesList[$key]; if($formatSpec == 'array') { return array($key => $val); } // Default (as per earlier implementations) - can be specified with // 'display' format. return $val; } }