PrimitiveEnumeration.class.php

Go to the documentation of this file.
00001 <?php
00002 /*****************************************************************************
00003  *   Copyright (C) 2006-2007 by Ivan Y. Khvostishkov, 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: PrimitiveEnumeration.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00016     final class PrimitiveEnumeration extends IdentifiablePrimitive
00017     {
00018         public function getList()
00019         {
00020             if ($this->value)
00021                 return $this->value->getObjectList();
00022             elseif ($this->default)
00023                 return $this->default->getObjectList();
00024             else {
00025                 return new $this->className(
00026                     call_user_func(array($this->className, 'getAnyId'))
00027                 );
00028             }
00029             
00030             Assert::isUnreachable();
00031         }
00032 
00037         public function of($class)
00038         {
00039             $className = $this->guessClassName($class);
00040             
00041             Assert::isTrue(
00042                 class_exists($className, true),
00043                 "knows nothing about '{$className}' class"
00044             );
00045             
00046             Assert::isTrue(
00047                 is_subclass_of($className, 'Enumeration'),
00048                 'non-enumeration child given'
00049             );
00050             
00051             $this->className = $className;
00052             
00053             return $this;
00054         }
00055         
00056         public function importValue(/* Identifiable */ $value)
00057         {
00058             if ($value)
00059                 Assert::isTrue(get_class($value) == $this->className);
00060             else
00061                 return parent::importValue(null);
00062             
00063             return $this->import(array($this->getName() => $value->getId()));
00064         }
00065         
00066         public function import($scope)
00067         {
00068             if (!$this->className)
00069                 throw new WrongStateException(
00070                     "no class defined for PrimitiveEnumeration '{$this->name}'"
00071                 );
00072                 
00073             $result = parent::import($scope);
00074             
00075             if ($result === true) {
00076                 try {
00077                     $this->value = new $this->className($this->value);
00078                 } catch (MissingElementException $e) {
00079                     $this->value = null;
00080                     
00081                     return false;
00082                 }
00083                 
00084                 return true;
00085             }
00086             
00087             return $result;
00088         }
00089     }
00090 ?>

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