PrimitiveList.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2004-2007 by Konstantin V. Arkhipov                     *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation; either version 3 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  ***************************************************************************/
00011 
00015     class PrimitiveList extends BasePrimitive implements ListedPrimitive
00016     {
00017         protected $list = array();
00018         
00019         public function getChoiceValue()
00020         {
00021             if ($this->value !== null)
00022                 return $this->list[$this->value];
00023             
00024             return null;
00025         }
00026         
00027         public function getActualChoiceValue()
00028         {
00029             if ($this->value !== null)
00030                 return $this->list[$this->value];
00031             
00032             return $this->list[$this->default];
00033         }
00034         
00038         public function setDefault($default)
00039         {
00040             Assert::isTrue(
00041                 $this->list
00042                 && array_key_exists(
00043                     $default,
00044                     $this->list
00045                 ),
00046                 
00047                 'can not find element with such index'
00048             );
00049             
00050             return parent::setDefault($default);
00051         }
00052         
00053         public function getList()
00054         {
00055             return $this->list;
00056         }
00057         
00061         public function setList($list)
00062         {
00063             $this->list = $list;
00064             
00065             return $this;
00066         }
00067         
00068         public function import($scope)
00069         {
00070             if (!parent::import($scope)) {
00071                 return null;
00072             }
00073             
00074             if (
00075                 (
00076                     is_string($scope[$this->name])
00077                     || is_integer($scope[$this->name])
00078                 )
00079                 && array_key_exists($scope[$this->name], $this->list)
00080             ) {
00081                 $this->value = $scope[$this->name];
00082                 
00083                 return true;
00084             }
00085             
00086             return false;
00087         }
00088     }
00089 ?>