summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
Diffstat (limited to 'framework')
-rw-r--r--framework/Log/TLogRouter.php123
-rw-r--r--framework/Web/UI/WebControls/TBaseValidator.php50
-rw-r--r--framework/core.php72
3 files changed, 227 insertions, 18 deletions
diff --git a/framework/Log/TLogRouter.php b/framework/Log/TLogRouter.php
new file mode 100644
index 00000000..9060e305
--- /dev/null
+++ b/framework/Log/TLogRouter.php
@@ -0,0 +1,123 @@
+<?php
+/*
+<module id="log" class="System.Log.LogRouter" ConfigFile="xxx">
+ <route class="TFileLogRoute" SizeLimit="111" Levels="xxx" Categories="xxx" />
+</module>
+*/
+class TLogRouter extends TModule
+{
+ const CONFIG_FILE_EXT='.xml';
+ private $_routes=array();
+
+ public function init($config)
+ {
+ foreach($config->getElementsByName('route') as $routeConfig)
+ {
+ $class=$routeConfig->removeAttribute('class');
+ $route=Prado::createComponent($class);
+ foreach($routeConfig->getAttributes() as $name=>$value)
+ $route->setSubproperty($name,$value);
+ }
+
+ $this->getApplication()->attachEventHandler('EndRequest',array($this,'collectLogs'));
+ }
+
+ public function getConfigFile()
+ {
+ return $this->_configFile;
+ }
+
+ public function setConfigFile($value)
+ {
+ if(($this->_configFile=Prado::getPathOfNamespace($value,self::LOG_FILE_EXT))===null)
+ throw new TConfigurationException('logrouter_configfile_invalid',$value);
+ }
+
+ public function collectLogs($param)
+ {
+ foreach($this->_routes as $route)
+ $route->collectLogs();
+ }
+}
+
+
+abstract class TLogRoute extends TComponent
+{
+ private static $_levelMap=array(
+ 'error'=>TLogger::ERROR,
+ 'debug'=>TLogger::DEBUG,
+ 'info'=>TLogger::INFO,
+ 'notice'=>TLogger::NOTICE,
+ 'warning'=>TLogger::WARNING,
+ 'error'=>TLogger::ERROR,
+ 'alert'=>TLogger::ALERT,
+ 'fatal'=>TLogger::FATAL
+ );
+ private $_levels=null;
+ private $_categories=null;
+
+ public function getLevels()
+ {
+ return $this->_levels;
+ }
+
+ public function setLevels($levels)
+ {
+ $this->_levels=null;
+ $levels=strtolower($levels);
+ foreach(explode(',',$levels) as $level)
+ {
+ $level=trim($level);
+ if(isset(self::$_levelMap[$level]))
+ $this->_levels|=self::$_levelMap[$level];
+ }
+ $this->_levels=$levels;
+ }
+
+ public function getCategories()
+ {
+ return $this->_categories;
+ }
+
+ public function setCategories($categories)
+ {
+ $this->_categories=null;
+ foreach(explode(',',$categories) as $category)
+ {
+ if(($category=trim($category))!=='')
+ $this->_categories[]=$category;
+ }
+ }
+
+ public function collectLogs()
+ {
+ $logs=Prado::getLogger()->getLogs($this->getLevels(),$this->getCategories());
+ $this->processLogs($logs);
+ }
+
+ protected function processLogs($logs);
+}
+
+class TFileLogRoute extends TLogRoute
+{
+ const LOG_FILE_EXT='.log';
+ private $_file;
+
+ public function getLogFile()
+ {
+ return $this->_file;
+ }
+
+ public function setLogFile($value)
+ {
+ if(($this->_file=Prado::getPathOfNamespace($value,self::LOG_FILE_EXT))===null)
+ throw new TConfigurationException('filelogroute_logfile_invalid',$value);
+ }
+
+ protected function processLogs($logs)
+ {
+ }
+}
+
+
+?> \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TBaseValidator.php b/framework/Web/UI/WebControls/TBaseValidator.php
index 0d88fc43..6326783a 100644
--- a/framework/Web/UI/WebControls/TBaseValidator.php
+++ b/framework/Web/UI/WebControls/TBaseValidator.php
@@ -99,6 +99,12 @@ abstract class TBaseValidator extends TLabel implements IValidator
$this->setForeColor('red');
}
+ protected function onInit($param)
+ {
+ parent::onInit($param);
+ $this->getPage()->getValidators()->add($this);
+ }
+
/**
* Adds attributes to renderer.
* @param THtmlWriter the renderer
@@ -133,8 +139,7 @@ abstract class TBaseValidator extends TLabel implements IValidator
{
$scripts = $this->getPage()->getClientScript();
$scriptKey = "prado:".get_class($this);
- if($this->getEnableClientScript()
- && !$script->isEndScriptRegistered($scriptKey))
+ if($this->getEnableClientScript() && !$scripts->isEndScriptRegistered($scriptKey))
{
$scripts->registerPradoScript('validator');
$js = "Prado.Validation.AddForm('{$this->Page->Form->ClientID}');";
@@ -254,7 +259,7 @@ abstract class TBaseValidator extends TLabel implements IValidator
*/
public function getFocusOnError()
{
- return $this->getViewState('FocusOnError',true);
+ return $this->getViewState('FocusOnError',false);
}
/**
@@ -318,6 +323,28 @@ abstract class TBaseValidator extends TLabel implements IValidator
$this->_isValid=TPropertyValue::ensureBoolean($value);
}
+ protected function getValidationTarget()
+ {
+ if(($id=$this->getControlToValidate())!=='')
+ return $this->findControl($id);
+ else
+ return null;
+ }
+
+ protected function getValidationValue($control)
+ {
+ if($control instanceof IValidatable)
+ {
+ $value=$control->getValidationValue();
+ if($value instanceof TListItem)
+ return $value->getValue();
+ else
+ return TPropertyValue::ensureString($value);
+ }
+ else
+ throw new TInvalidDataTypeException('basevalidator_validatable_required');
+ }
+
/**
* Validates the specified control.
* Do not override this method. Override {@link evaluateIsValid} instead.
@@ -326,22 +353,9 @@ abstract class TBaseValidator extends TLabel implements IValidator
public function validate()
{
$this->setIsValid(true);
- if($this->getVisible(true) && $this->getEnabled())
- {
- $valid=$this->evaluateIsValid();
- $this->setValid($valid);
- }
- if($this->isVisible() && $this->isEnabled() && strlen($this->getControlToValidate()))
- {
+ $control=$this->getValidationTarget();
+ if($control && $this->getVisible(true) && $this->getEnabled())
$valid=$this->evaluateIsValid();
- $this->setValid($valid);
- return $valid;
- }
- else
- {
- $this->setValid(true);
- return true;
- }
}
/**
diff --git a/framework/core.php b/framework/core.php
index 08481d09..3be75010 100644
--- a/framework/core.php
+++ b/framework/core.php
@@ -374,6 +374,10 @@ class PradoBase
* @var TApplication the application instance
*/
private static $_application=null;
+ /**
+ * @var TLogger logger instance
+ */
+ private static $_logger=null;
/**
* @return string the version of Prado framework
@@ -718,6 +722,74 @@ class PradoBase
$logger->info($msg);
return $logger;
}
+
+ public static function log($msg,$level,$category='Uncategorized')
+ {
+ if(self::$_logger===null)
+ self::$_logger=new TLogger;
+ self::$_logger->log($msg,$level,$category);
+ }
+
+ public static function getLogger()
+ {
+ if(self::$_logger===null)
+ self::$_logger=new TLogger;
+ return self::$_logger;
+ }
+}
+
+class TLogger extends TComponent
+{
+ const DEBUG=0x01;
+ const INFO=0x02;
+ const NOTICE=0x04;
+ const WARNING=0x08;
+ const ERROR=0x10;
+ const ALERT=0x20;
+ const FATAL=0x40;
+ private $_logs=array();
+ private $_levels;
+ private $_categories;
+
+ public function log($message,$level,$category='Uncategorized')
+ {
+ $this->_logs[]=array($message,$level,$category,microtime());
+ }
+
+ public function getLogs($levels=null,$categories=null)
+ {
+ $this->_levels=$levels;
+ $this->_categories=$categories;
+ if(empty($levels) && empty($categories))
+ return $this->_logs;
+ else if(empty($levels))
+ return array_values(array_filter(array_filter($this->_logs,array($this,'filterByCategories'))));
+ else if(empty($categories))
+ return array_values(array_filter(array_filter($this->_logs,array($this,'filterByLevels'))));
+ else
+ {
+ $ret=array_values(array_filter(array_filter($this->_logs,array($this,'filterByLevels'))));
+ return array_values(array_filter(array_filter($ret,array($this,'filterByCategories'))));
+ }
+ }
+
+ private function filterByCategories($value)
+ {
+ foreach($this->_categories as $category)
+ {
+ if(strpos($value[2],$category)===0)
+ return $value;
+ }
+ return false;
+ }
+
+ private function filterByLevels($value)
+ {
+ if($level & $this->_levels)
+ return $value;
+ else
+ return false;
+ }
}
?> \ No newline at end of file