Revision: 211
http://sourceforge.net/p/beeframework/code/211
Author: m_plomer
Date: 2014-09-10 17:13:01 +0000 (Wed, 10 Sep 2014)
Log Message:
-----------
- D2 EnumType: fixed compatibility with early 5.3 version (which exhibit quirks in reflected access to late statically bound methods)
Modified Paths:
--------------
trunk/framework/Bee/Persistence/Doctrine2/Types/EnumType.php
Modified: trunk/framework/Bee/Persistence/Doctrine2/Types/EnumType.php
===================================================================
--- trunk/framework/Bee/Persistence/Doctrine2/Types/EnumType.php 2014-09-08 13:49:56 UTC (rev 210)
+++ trunk/framework/Bee/Persistence/Doctrine2/Types/EnumType.php 2014-09-10 17:13:01 UTC (rev 211)
@@ -27,11 +27,6 @@
const ENUM_BASE_TYPE = 'Bee\Utils\EnumBase';
/**
- * @var \ReflectionClass
- */
- private $reflClass;
-
- /**
* @return string
*/
protected static function getEnumClassName() {
@@ -39,7 +34,6 @@
}
public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform) {
- if (!$this->reflClass) self::init();
$values = array_map(function ($val) {
return "'" . $val . "'";
}, call_user_func(array(static::getEnumClassName(), 'getValues')));
@@ -47,16 +41,14 @@
}
public function convertToPHPValue($value, AbstractPlatform $platform) {
- if (!$this->reflClass) self::init();
- return $this->reflClass->getMethod('get')->invoke(null, $value);
+ return call_user_func(array(static::getEnumClassName(), 'get'));
}
public function convertToDatabaseValue($value, AbstractPlatform $platform) {
- if (!$this->reflClass) self::init();
- if(is_null($val)) {
+ if(is_null($value)) {
return $value;
}
- if (!$this->reflClass->isInstance($value)) {
+ if (get_class($value) != static::getEnumClassName()) {
throw new \UnexpectedValueException('Not a valid enum element for "' . static::getEnumClassName() . '": ' . $value);
}
// check if value is valid
@@ -65,13 +57,6 @@
return $value->val();
}
- private function init() {
- $this->reflClass = new \ReflectionClass(static::getEnumClassName());
- if (!$this->reflClass->isSubclassOf(self::ENUM_BASE_TYPE)) {
- throw new \UnexpectedValueException('"' . $this->reflClass . '" is not a subclass of "' . self::ENUM_BASE_TYPE . '"');
- }
- }
-
public function getName() {
return self::getEnumName();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|