PrimitiveEnumerationByValue.class.php

Go to the documentation of this file.
00001 <?php
00002 /*****************************************************************************
00003  *   Copyright (C) 2009 by Denis M. Gabaidulin                               *
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     final class PrimitiveEnumerationByValue extends PrimitiveEnumeration
00016     {
00017         public function import($scope)
00018         {
00019             if (!$this->className)
00020                 throw new WrongStateException(
00021                     "no class defined for PrimitiveEnumeration '{$this->name}'"
00022                 );
00023             
00024             if (isset($scope[$this->name])) {
00025                 $scopedValue = urldecode($scope[$this->name]);
00026                 
00027                 $anyId =
00028                     ClassUtils::callStaticMethod($this->className.'::getAnyId');
00029                 
00030                 $object = new $this->className($anyId);
00031                 
00032                 $names = $object->getNameList();
00033                 
00034                 foreach ($names as $key => $value) {
00035                     if ($value == $scopedValue) {
00036                         try {
00037                             $this->value = new $this->className($key);
00038                         } catch (MissingElementException $e) {
00039                             $this->value = null;
00040                             return false;
00041                         }
00042                         
00043                         return true;
00044                     }
00045                 }
00046                 
00047                 return false;
00048             }
00049             
00050             return null;
00051         }
00052     }
00053 ?>