[Beeframework-svn] SF.net SVN: beeframework:[72] trunk/framework/Bee
Brought to you by:
b_hartmann,
m_plomer
From: <m_p...@us...> - 2013-08-27 09:05:47
|
Revision: 72 http://sourceforge.net/p/beeframework/code/72 Author: m_plomer Date: 2013-08-27 09:05:44 +0000 (Tue, 27 Aug 2013) Log Message: ----------- - EnumBase / EnumType fixes - classloading fix Modified Paths: -------------- trunk/framework/Bee/Framework.php trunk/framework/Bee/Persistence/Doctrine2/Types/EnumType.php trunk/framework/Bee/Utils/EnumBase.php Modified: trunk/framework/Bee/Framework.php =================================================================== --- trunk/framework/Bee/Framework.php 2013-08-25 02:09:27 UTC (rev 71) +++ trunk/framework/Bee/Framework.php 2013-08-27 09:05:44 UTC (rev 72) @@ -168,7 +168,7 @@ } foreach(self::getClassFileLocations($className) as $loc) { - include $loc; + include_once $loc; if (class_exists($className, false) || interface_exists($className, false)) { return true; } Modified: trunk/framework/Bee/Persistence/Doctrine2/Types/EnumType.php =================================================================== --- trunk/framework/Bee/Persistence/Doctrine2/Types/EnumType.php 2013-08-25 02:09:27 UTC (rev 71) +++ trunk/framework/Bee/Persistence/Doctrine2/Types/EnumType.php 2013-08-27 09:05:44 UTC (rev 72) @@ -38,8 +38,11 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) { if (!$this->reflClass) self::init(); + if(is_null($val)) { + return $value; + } if (!$this->reflClass->isInstance($value)) { - throw new \UnexpectedValueException('Not a valid enum element for "' . self::ENUM_BASE_TYPE . '": ' . $value); + throw new \UnexpectedValueException('Not a valid enum element for "' . static::getEnumClassName() . '": ' . $value); } // check if value is valid self::convertToPHPValue($value->val(), $platform); Modified: trunk/framework/Bee/Utils/EnumBase.php =================================================================== --- trunk/framework/Bee/Utils/EnumBase.php 2013-08-25 02:09:27 UTC (rev 71) +++ trunk/framework/Bee/Utils/EnumBase.php 2013-08-27 09:05:44 UTC (rev 72) @@ -24,22 +24,17 @@ abstract class EnumBase { /** - * @var ReflectionClass - */ - private static $reflClass = null; - - /** * @var array */ private static $valueToName = null; /** - * @var EnumBase + * @var EnumBase[] */ private static $instancesByValue = null; /** - * @var EnumBase + * @var EnumBase[] */ private static $instancesByOid = null; @@ -63,8 +58,8 @@ * @return array */ public static function getValues() { - self::init(); - return array_keys(self::$valueToName); + static::init(); + return array_keys(self::$valueToName[get_called_class()]); } /** @@ -85,31 +80,36 @@ * @throws \UnexpectedValueException */ public static function get($value) { - self::init(); - if(!isset(self::$valueToName[$value])) { - throw new \UnexpectedValueException('Invalid value "' . $value . '" for enum ' . self::$reflClass->getShortName()); + if(is_null($value)) { + return $value; } + static::init(); + $calledClass = get_called_class(); + if(!isset(self::$valueToName[$calledClass][$value])) { + throw new \UnexpectedValueException('Invalid value "' . $value . '" for enum ' . $calledClass); + } - if(!isset(self::$instancesByValue[$value])) { - $name = self::$valueToName[$value]; - $className = self::$reflClass->getName(); - $instanceClassName = class_exists($className . '_' . $name, false) ? $className . '_' . $name : $className; + if(!isset(self::$instancesByValue[$calledClass][$value])) { + $name = self::$valueToName[$calledClass][$value]; + $instanceClassName = class_exists($calledClass . '_' . $name, false) ? $calledClass . '_' . $name : $calledClass; $inst = new $instanceClassName($value); - self::$instancesByValue[$value] = $inst; + self::$instancesByValue[$calledClass][$value] = $inst; self::$instancesByOid[spl_object_hash($inst)] = $inst; } - return self::$instancesByValue[$value]; + return self::$instancesByValue[$calledClass][$value]; } private static function init() { - if(is_null(self::$reflClass)) { - self::$reflClass = new \ReflectionClass(new static(false)); - $constants = self::$reflClass->getConstants(); - self::$valueToName = array_flip($constants); - if(count($constants) !== count(self::$valueToName)) { - throw new \UnexpectedValueException('Invalid enum definition ' . self::$reflClass->getName() .' : const values probably not unique'); + $calledClass = get_called_class(); + if(!isset(self::$valueToName[$calledClass])) { + $reflClass = new \ReflectionClass($calledClass); + $constants = $reflClass->getConstants(); + $flipped = array_flip($constants); + if(count($constants) !== count($flipped)) { + throw new \UnexpectedValueException('Invalid enum definition ' . $reflClass->getName() .' : const values probably not unique'); } + self::$valueToName[$calledClass] = $flipped; } } @@ -119,4 +119,3 @@ private function __wakeup() { } } - \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |