summaryrefslogtreecommitdiff
path: root/framework/Data
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Data')
-rw-r--r--framework/Data/ActiveRecord/TActiveRecord.php68
-rw-r--r--framework/Data/ActiveRecord/TActiveRecordConfig.php36
-rw-r--r--framework/Data/ActiveRecord/TActiveRecordManager.php29
3 files changed, 127 insertions, 6 deletions
diff --git a/framework/Data/ActiveRecord/TActiveRecord.php b/framework/Data/ActiveRecord/TActiveRecord.php
index 24227586..9ec1a4b3 100644
--- a/framework/Data/ActiveRecord/TActiveRecord.php
+++ b/framework/Data/ActiveRecord/TActiveRecord.php
@@ -1,6 +1,6 @@
<?php
/**
- * TActiveRecord and TActiveRecordEventParameter class file.
+ * TActiveRecord, TActiveRecordEventParameter, TActiveRecordInvalidFinderResult class file.
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
* @link http://www.pradosoft.com/
@@ -189,6 +189,15 @@ abstract class TActiveRecord extends TComponent
*/
protected $_connection; // use protected so that serialization is fine
+
+ /**
+ * Defaults to 'null'
+ *
+ * @var TActiveRecordInvalidFinderResult
+ * @since 3.1.5
+ */
+ private $_invalidFinderResult = null;
+
/**
* Prevent __call() method creating __sleep() when serializing.
*/
@@ -829,7 +838,12 @@ abstract class TActiveRecord extends TComponent
else if($delete=strncasecmp($method,'deleteallby',11)===0)
$condition = $method[11]==='_' ? substr($method,12) : substr($method,11);
else
- return null;//throw new TActiveRecordException('ar_invalid_finder_method',$method);
+ {
+ if($this->getInvalidFinderResult() == TActiveRecordInvalidFinderResult::Exception)
+ throw new TActiveRecordException('ar_invalid_finder_method',$method);
+ else
+ return null;
+ }
$criteria = $this->getRecordGateway()->getCommand($this)->createCriteriaFromString($method, $condition, $args);
if($delete)
@@ -839,6 +853,34 @@ abstract class TActiveRecord extends TComponent
}
/**
+ * @return TActiveRecordInvalidFinderResult Defaults to '{@link TActiveRecordInvalidFinderResult::Null Null}'.
+ * @see TActiveRecordManager::getInvalidFinderResult
+ * @since 3.1.5
+ */
+ public function getInvalidFinderResult()
+ {
+ if($this->_invalidFinderResult !== null)
+ return $this->_invalidFinderResult;
+
+ return self::getRecordManager()->getInvalidFinderResult();
+ }
+
+ /**
+ * Define the way an active record finder react if an invalid magic-finder invoked
+ *
+ * @param TActiveRecordInvalidFinderResult|null
+ * @see TActiveRecordManager::setInvalidFinderResult
+ * @since 3.1.5
+ */
+ public function setInvalidFinderResult($value)
+ {
+ if($value === null)
+ $this->_invalidFinderResult = null;
+ else
+ $this->_invalidFinderResult = TPropertyValue::ensureEnum($value, 'TActiveRecordInvalidFinderResult');
+ }
+
+ /**
* Create a new TSqlCriteria object from a string $criteria. The $args
* are additional parameters and are used in place of the $parameters
* if $parameters is not an array and $args is an arrary.
@@ -1021,3 +1063,25 @@ class TActiveRecordChangeEventParameter extends TEventParameter
}
}
+/**
+ * TActiveRecordInvalidFinderResult class.
+ * TActiveRecordInvalidFinderResult defines the enumerable type for possible results
+ * if an invalid {@link TActiveRecord::__call magic-finder} invoked.
+ *
+ * The following enumerable values are defined:
+ * - Null: return null (default)
+ * - Exception: throws a TActiveRecordException
+ *
+ * @author Yves Berkholz <godzilla80@gmx.net>
+ * @version $Id$
+ * @package System.Data.ActiveRecord
+ * @see TActiveRecordManager::setInvalidFinderResult
+ * @see TActiveRecordConfig::setInvalidFinderResult
+ * @see TActiveRecord::setInvalidFinderResult
+ * @since 3.1.5
+ */
+class TActiveRecordInvalidFinderResult extends TEnumerable
+{
+ const Null = 'Null';
+ const Exception = 'Exception';
+}
diff --git a/framework/Data/ActiveRecord/TActiveRecordConfig.php b/framework/Data/ActiveRecord/TActiveRecordConfig.php
index 63f05aef..fb57fd33 100644
--- a/framework/Data/ActiveRecord/TActiveRecordConfig.php
+++ b/framework/Data/ActiveRecord/TActiveRecordConfig.php
@@ -11,6 +11,7 @@
*/
Prado::using('System.Data.TDataSourceConfig');
+Prado::using('System.Data.ActiveRecord.TActiveRecordManager');
/**
* TActiveRecordConfig module configuration class.
@@ -74,17 +75,25 @@ class TActiveRecordConfig extends TDataSourceConfig
private $_enableCache=false;
/**
+ * Defaults to '{@link TActiveRecordInvalidFinderResult::Null Null}'
+ *
+ * @var TActiveRecordInvalidFinderResult
+ * @since 3.1.5
+ */
+ private $_invalidFinderResult = TActiveRecordInvalidFinderResult::Null;
+
+ /**
* Initialize the active record manager.
* @param TXmlDocument xml configuration.
*/
public function init($xml)
{
parent::init($xml);
- Prado::using('System.Data.ActiveRecord.TActiveRecordManager');
$manager = TActiveRecordManager::getInstance();
if($this->getEnableCache())
$manager->setCache($this->getApplication()->getCache());
$manager->setDbConnection($this->getDbConnection());
+ $manager->setInvalidFinderResult($this->getInvalidFinderResult());
}
/**
@@ -103,5 +112,26 @@ class TActiveRecordConfig extends TDataSourceConfig
{
return $this->_enableCache;
}
-}
-
+
+ /**
+ * @return TActiveRecordInvalidFinderResult Defaults to '{@link TActiveRecordInvalidFinderResult::Null Null}'.
+ * @see setInvalidFinderResult
+ * @since 3.1.5
+ */
+ public function getInvalidFinderResult()
+ {
+ return $this->_invalidFinderResult;
+ }
+
+ /**
+ * Define the way an active record finder react if an invalid magic-finder invoked
+ *
+ * @param TActiveRecordInvalidFinderResult
+ * @see getInvalidFinderResult
+ * @since 3.1.5
+ */
+ public function setInvalidFinderResult($value)
+ {
+ $this->_invalidFinderResult = TPropertyValue::ensureEnum($value, 'TActiveRecordInvalidFinderResult');
+ }
+} \ No newline at end of file
diff --git a/framework/Data/ActiveRecord/TActiveRecordManager.php b/framework/Data/ActiveRecord/TActiveRecordManager.php
index 9912e7ff..cba746ec 100644
--- a/framework/Data/ActiveRecord/TActiveRecordManager.php
+++ b/framework/Data/ActiveRecord/TActiveRecordManager.php
@@ -44,6 +44,14 @@ class TActiveRecordManager extends TComponent
private $_cache;
/**
+ * Defaults to '{@link TActiveRecordInvalidFinderResult::Null Null}'
+ *
+ * @var TActiveRecordInvalidFinderResult
+ * @since 3.1.5
+ */
+ private $_invalidFinderResult = TActiveRecordInvalidFinderResult::Null;
+
+ /**
* @return ICache application cache.
*/
public function getCache()
@@ -106,6 +114,25 @@ class TActiveRecordManager extends TComponent
{
return new TActiveRecordGateway($this);
}
-}
+ /**
+ * @return TActiveRecordInvalidFinderResult Defaults to '{@link TActiveRecordInvalidFinderResult::Null Null}'.
+ * @since 3.1.5
+ * @see setInvalidFinderResult
+ */
+ public function getInvalidFinderResult()
+ {
+ return $this->_invalidFinderResult;
+ }
+ /**
+ * Define the way an active record finder react if an invalid magic-finder invoked
+ * @param TActiveRecordInvalidFinderResult
+ * @since 3.1.5
+ * @see getInvalidFinderResult
+ */
+ public function setInvalidFinderResult($value)
+ {
+ $this->_invalidFinderResult = TPropertyValue::ensureEnum($value, 'TActiveRecordInvalidFinderResult');
+ }
+}