00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00016 class PrimitiveList extends BasePrimitive implements ListedPrimitive
00017 {
00018 protected $list = array();
00019
00020 public function getChoiceValue()
00021 {
00022 if ($this->value !== null)
00023 return $this->list[$this->value];
00024
00025 return null;
00026 }
00027
00028 public function getActualChoiceValue()
00029 {
00030 if ($this->value !== null)
00031 return $this->list[$this->value];
00032
00033 return $this->list[$this->default];
00034 }
00035
00039 public function setDefault($default)
00040 {
00041 Assert::isTrue(
00042 $this->list
00043 && array_key_exists(
00044 $default,
00045 $this->list
00046 ),
00047
00048 'can not find element with such index'
00049 );
00050
00051 return parent::setDefault($default);
00052 }
00053
00054 public function getList()
00055 {
00056 return $this->list;
00057 }
00058
00062 public function setList($list)
00063 {
00064 $this->list = $list;
00065
00066 return $this;
00067 }
00068
00069 public function import($scope)
00070 {
00071 if (!parent::import($scope)) {
00072 return null;
00073 }
00074
00075 if (
00076 (
00077 is_string($scope[$this->name])
00078 || is_integer($scope[$this->name])
00079 )
00080 && array_key_exists($scope[$this->name], $this->list)
00081 ) {
00082 $this->value = $scope[$this->name];
00083
00084 return true;
00085 }
00086
00087 return false;
00088 }
00089 }
00090 ?>