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 /* $Id: PrimitiveList.class.php 4687 2007-12-09 18:57:18Z voxus $ */
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 ?>

Generated on Sun Dec 9 21:56:23 2007 for onPHP by  doxygen 1.5.4