00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
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( $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 ?>