summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--HISTORY1
-rw-r--r--framework/Data/ActiveRecord/TActiveRecordConfig.php66
-rw-r--r--framework/Data/ActiveRecord/TActiveRecordManager.php27
3 files changed, 92 insertions, 2 deletions
diff --git a/HISTORY b/HISTORY
index d4ed8895..23e3ab83 100644
--- a/HISTORY
+++ b/HISTORY
@@ -10,6 +10,7 @@ EHN: Add second parameter to THttpResponse::appendHeader whether the header shou
ENH: Add THttpSession::regenerate() to update the current session id with a newly generated one (Yves)
CHG: Remove TReflectionClass and all references since equals ReflectionClass (Yves)
CHG: Modifiy TTemplate::parseAttributes to allow definition of "HTML5 Custom Data Attributes (data-*)" e.g Attributes.data-custom-value="foobar" (Yves)
+EHN: Modify TActiveRecordConfig & TActiveRecordManager to allow custom subclassing of System.Data.ActiveRecord.TActiveRecordManager & System.Data.ActiveRecord.TActiveRecordGateway (Yves)
Version 3.1.9 June 3, 2011
BUG: Issue#280 - Documentation has been updated
diff --git a/framework/Data/ActiveRecord/TActiveRecordConfig.php b/framework/Data/ActiveRecord/TActiveRecordConfig.php
index f9a483ec..d5512009 100644
--- a/framework/Data/ActiveRecord/TActiveRecordConfig.php
+++ b/framework/Data/ActiveRecord/TActiveRecordConfig.php
@@ -72,6 +72,26 @@ Prado::using('System.Data.ActiveRecord.TActiveRecordManager');
*/
class TActiveRecordConfig extends TDataSourceConfig
{
+ const DEFAULT_MANAGER_CLASS = 'System.Data.ActiveRecord.TActiveRecordManager';
+ const DEFAULT_GATEWAY_CLASS = 'System.Data.ActiveRecord.TActiveRecordGateway';
+
+ /**
+ * Defaults to {@link TActiveRecordConfig::DEFAULT_GATEWAY_CLASS DEFAULT_MANAGER_CLASS}
+ * @var string
+ */
+ private $_managerClass = self::DEFAULT_MANAGER_CLASS;
+
+ /**
+ * Defaults to {@link TActiveRecordConfig::DEFAULT_GATEWAY_CLASS DEFAULT_GATEWAY_CLASS}
+ * @var string
+ */
+ private $_gatewayClass = self::DEFAULT_GATEWAY_CLASS;
+
+ /**
+ * @var TActiveRecordManager
+ */
+ private $_manager = null;
+
private $_enableCache=false;
/**
@@ -89,11 +109,55 @@ class TActiveRecordConfig extends TDataSourceConfig
public function init($xml)
{
parent::init($xml);
- $manager = TActiveRecordManager::getInstance();
+ $manager = $this -> getManager();
if($this->getEnableCache())
$manager->setCache($this->getApplication()->getCache());
$manager->setDbConnection($this->getDbConnection());
$manager->setInvalidFinderResult($this->getInvalidFinderResult());
+ $manager->setGatewayClass($this->getGatewayClass());
+ }
+
+ /**
+ * @return TActiveRecordManager
+ */
+ public function getManager() {
+ if($this->_manager === null)
+ $this->_manager = Prado::createComponent($this -> getManagerClass());
+ return TActiveRecordManager::getInstance($this->_manager);
+ }
+
+ /**
+ * Set implementation class of ActiveRecordManager
+ * @param string $value
+ */
+ public function setManagerClass($value)
+ {
+ $this->_managerClass = TPropertyValue::ensureString($value);
+ }
+
+ /**
+ * @return string the implementation class of ActiveRecordManager. Defaults to {@link TActiveRecordConfig::DEFAULT_GATEWAY_CLASS DEFAULT_MANAGER_CLASS}
+ */
+ public function getManagerClass()
+ {
+ return $this->_managerClass;
+ }
+
+ /**
+ * Set implementation class of ActiveRecordGateway
+ * @param string $value
+ */
+ public function setGatewayClass($value)
+ {
+ $this->_gatewayClass = TPropertyValue::ensureString($value);
+ }
+
+ /**
+ * @return string the implementation class of ActiveRecordGateway. Defaults to {@link TActiveRecordConfig::DEFAULT_GATEWAY_CLASS DEFAULT_GATEWAY_CLASS}
+ */
+ public function getGatewayClass()
+ {
+ return $this->_gatewayClass;
}
/**
diff --git a/framework/Data/ActiveRecord/TActiveRecordManager.php b/framework/Data/ActiveRecord/TActiveRecordManager.php
index d39ef69e..1a1c1f37 100644
--- a/framework/Data/ActiveRecord/TActiveRecordManager.php
+++ b/framework/Data/ActiveRecord/TActiveRecordManager.php
@@ -37,6 +37,14 @@ Prado::using('System.Data.ActiveRecord.TActiveRecordGateway');
*/
class TActiveRecordManager extends TComponent
{
+ const DEFAULT_GATEWAY_CLASS = 'System.Data.ActiveRecord.TActiveRecordGateway';
+
+ /**
+ * Defaults to {@link TActiveRecordManager::DEFAULT_GATEWAY_CLASS DEFAULT_GATEWAY_CLASS}
+ * @var string
+ */
+ private $_gatewayClass = self::DEFAULT_GATEWAY_CLASS;
+
private $_gateway;
private $_meta=array();
private $_connection;
@@ -112,7 +120,24 @@ class TActiveRecordManager extends TComponent
*/
protected function createRecordGateway()
{
- return new TActiveRecordGateway($this);
+ return Prado::createComponent($this->getGatewayClass(), $this);
+ }
+
+ /**
+ * Set implementation class of ActiveRecordGateway
+ * @param string $value
+ */
+ public function setGatewayClass($value)
+ {
+ $this->_gatewayClass = (string)$value;
+ }
+
+ /**
+ * @return string the implementation class of ActiveRecordGateway. Defaults to {@link TActiveRecordManager::DEFAULT_GATEWAY_CLASS DEFAULT_GATEWAY_CLASS}
+ */
+ public function getGatewayClass()
+ {
+ return $this->_gatewayClass;
}
/**