Revision: 60
http://sourceforge.net/p/beeframework/code/60
Author: m_plomer
Date: 2013-08-24 12:48:31 +0000 (Sat, 24 Aug 2013)
Log Message:
-----------
- fixed Doctrine2 EnumType
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 2013-08-24 12:32:07 UTC (rev 59)
+++ trunk/framework/Bee/Persistence/Doctrine2/Types/EnumType.php 2013-08-24 12:48:31 UTC (rev 60)
@@ -10,12 +10,26 @@
abstract class EnumType extends Type
{
protected $name;
- protected $values = array();
+ /**
+ * @var \ReflectionClass
+ */
+ protected $reflClass;
+
+ private $values;
+
+ public function __construct() {
+ $this->reflClass = new \ReflectionClass($this);
+ $this->values = $this->reflClass->getConstants();
+ }
+
+ protected function getValues() {
+ return $this->values;
+ }
+
public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
- $values = array_map(function($val) { return "'".$val."'"; }, $this->values);
-
+ $values = array_map(function($val) { return "'".$val."'"; }, $this->getValues());
return "ENUM(".implode(", ", $values).") COMMENT '(DC2Type:".$this->name.")'";
}
@@ -26,7 +40,8 @@
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
- if (!in_array($value, $this->values)) {
+
+ if (!in_array($value, $this->getValues())) {
throw new \InvalidArgumentException("Invalid '".$this->name."' value.");
}
return $value;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|