From 01e41f3d27dafa8c2243fcc709512f30bc9b3e95 Mon Sep 17 00:00:00 2001 From: zYne Date: Thu, 1 Nov 2007 22:52:40 +0000 Subject: [PATCH] added possibility for setting user-defined params --- lib/Doctrine.php | 21 +++++++++++---------- lib/Doctrine/Configurable.php | 31 +++++++++++++++++++++++++++++++ lib/Doctrine/Manager.php | 31 ++++++++++++++++--------------- 3 files changed, 58 insertions(+), 25 deletions(-) diff --git a/lib/Doctrine.php b/lib/Doctrine.php index c66015936..ba3d24179 100644 --- a/lib/Doctrine.php +++ b/lib/Doctrine.php @@ -176,16 +176,17 @@ final class Doctrine const ATTR_USE_NATIVE_ENUM = 117; const ATTR_DEFAULT_SEQUENCE = 133; - const ATTR_FETCHMODE = 118; - const ATTR_NAME_PREFIX = 121; - const ATTR_CREATE_TABLES = 122; - const ATTR_COLL_LIMIT = 123; + const ATTR_FETCHMODE = 118; + const ATTR_NAME_PREFIX = 121; + const ATTR_CREATE_TABLES = 122; + const ATTR_COLL_LIMIT = 123; - const ATTR_CACHE = 150; - const ATTR_CACHE_LIFESPAN = 151; - const ATTR_LOAD_REFERENCES = 153; - const ATTR_RECORD_LISTENER = 154; - const ATTR_THROW_EXCEPTIONS = 155; + const ATTR_CACHE = 150; + const ATTR_CACHE_LIFESPAN = 151; + const ATTR_LOAD_REFERENCES = 153; + const ATTR_RECORD_LISTENER = 154; + const ATTR_THROW_EXCEPTIONS = 155; + const ATTR_DEFAULT_PARAM_NAMESPACE = 156; /** * LIMIT CONSTANTS @@ -1040,4 +1041,4 @@ final class Doctrine return mkdir($path, $mode, true); } -} \ No newline at end of file +} diff --git a/lib/Doctrine/Configurable.php b/lib/Doctrine/Configurable.php index 8ea432d39..f695ac861 100644 --- a/lib/Doctrine/Configurable.php +++ b/lib/Doctrine/Configurable.php @@ -50,6 +50,11 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable * implementation classes */ protected $_impl = array(); + + /** + * @var array $_params an array of user defined parameters + */ + protected $_params = array(); /** * setAttribute @@ -116,6 +121,7 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable case Doctrine::ATTR_LOAD_REFERENCES: case Doctrine::ATTR_RECORD_LISTENER: case Doctrine::ATTR_THROW_EXCEPTIONS: + case Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE: break; case Doctrine::ATTR_SEQCOL_NAME: @@ -143,6 +149,31 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable } + public function setParam($name, $value, $namespace = null) + { + if ($namespace = null) { + $namespace = $this->getAttribute(Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE); + } + + $this->_params[$namespace][$name] = $value; + + return $this; + } + + public function getParam($name, $value, $namespace) + { + if ($namespace = null) { + $namespace = $this->getAttribute(Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE); + } + + if ( ! isset($this->_params[$name])) { + if (isset($this->parent)) { + return $this->parent->getParam($name); + } + return null; + } + return $this->_params[$name]; + } /** * setImpl * binds given class to given template name diff --git a/lib/Doctrine/Manager.php b/lib/Doctrine/Manager.php index 0808c6681..5d9ff9dce 100644 --- a/lib/Doctrine/Manager.php +++ b/lib/Doctrine/Manager.php @@ -90,21 +90,22 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera if ( ! $init) { $init = true; $attributes = array( - Doctrine::ATTR_CACHE => null, - Doctrine::ATTR_LOAD_REFERENCES => true, - Doctrine::ATTR_LISTENER => new Doctrine_EventListener(), - Doctrine::ATTR_RECORD_LISTENER => new Doctrine_Record_Listener(), - Doctrine::ATTR_THROW_EXCEPTIONS => true, - Doctrine::ATTR_VALIDATE => Doctrine::VALIDATE_NONE, - Doctrine::ATTR_QUERY_LIMIT => Doctrine::LIMIT_RECORDS, - Doctrine::ATTR_IDXNAME_FORMAT => "%s_idx", - Doctrine::ATTR_SEQNAME_FORMAT => "%s_seq", - Doctrine::ATTR_TBLNAME_FORMAT => "%s", - Doctrine::ATTR_QUOTE_IDENTIFIER => false, - Doctrine::ATTR_SEQCOL_NAME => 'id', - Doctrine::ATTR_PORTABILITY => Doctrine::PORTABILITY_ALL, - Doctrine::ATTR_EXPORT => Doctrine::EXPORT_ALL, - Doctrine::ATTR_DECIMAL_PLACES => 2, + Doctrine::ATTR_CACHE => null, + Doctrine::ATTR_LOAD_REFERENCES => true, + Doctrine::ATTR_LISTENER => new Doctrine_EventListener(), + Doctrine::ATTR_RECORD_LISTENER => new Doctrine_Record_Listener(), + Doctrine::ATTR_THROW_EXCEPTIONS => true, + Doctrine::ATTR_VALIDATE => Doctrine::VALIDATE_NONE, + Doctrine::ATTR_QUERY_LIMIT => Doctrine::LIMIT_RECORDS, + Doctrine::ATTR_IDXNAME_FORMAT => "%s_idx", + Doctrine::ATTR_SEQNAME_FORMAT => "%s_seq", + Doctrine::ATTR_TBLNAME_FORMAT => "%s", + Doctrine::ATTR_QUOTE_IDENTIFIER => false, + Doctrine::ATTR_SEQCOL_NAME => 'id', + Doctrine::ATTR_PORTABILITY => Doctrine::PORTABILITY_ALL, + Doctrine::ATTR_EXPORT => Doctrine::EXPORT_ALL, + Doctrine::ATTR_DECIMAL_PLACES => 2, + Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE => 'doctrine', ); foreach ($attributes as $attribute => $value) { $old = $this->getAttribute($attribute);