From 77750ab4cc4c0055a29352334a9357d74e3957d3 Mon Sep 17 00:00:00 2001 From: wei <> Date: Thu, 5 Jan 2006 01:13:15 +0000 Subject: coreLog instrumentation. --- .gitattributes | 4 +- demos/quickstart/protected/application.xml | 13 +-- demos/quickstart/protected/logs/logger.xml | 9 -- framework/Collections/TList.php | 8 ++ framework/Log/TEventLog.php | 40 ++++++-- framework/Log/TEzcLogger.php | 133 --------------------------- framework/Log/TLog.php | 13 --- framework/Log/TLogManager.php | 141 +++++++++++++++++++++++++++++ framework/TApplication.php | 6 +- framework/Web/Services/TPageService.php | 4 + framework/Web/THttpRequest.php | 1 + framework/Web/THttpResponse.php | 2 + framework/Web/UI/TAssetManager.php | 1 + framework/Web/UI/TControl.php | 3 + framework/Web/UI/TForm.php | 1 + framework/Web/UI/TPage.php | 24 ++++- framework/Web/UI/TPageStatePersister.php | 2 + framework/Web/UI/TTemplateControl.php | 3 +- framework/Web/UI/TThemeManager.php | 1 + framework/core.php | 12 +++ framework/prado.php | 120 ++++++++++++------------ tools/phpbuilder/build.php | 54 ++++++++++- tools/phpbuilder/files.txt | 2 +- 23 files changed, 352 insertions(+), 245 deletions(-) delete mode 100644 demos/quickstart/protected/logs/logger.xml delete mode 100644 framework/Log/TEzcLogger.php delete mode 100644 framework/Log/TLog.php create mode 100644 framework/Log/TLogManager.php diff --git a/.gitattributes b/.gitattributes index 0175b999..8c756097 100644 --- a/.gitattributes +++ b/.gitattributes @@ -31,7 +31,6 @@ demos/quickstart/protected/controls/SampleLayout.tpl -text demos/quickstart/protected/controls/TTextHighlighter.php -text demos/quickstart/protected/controls/TopicList.php -text demos/quickstart/protected/controls/TopicList.tpl -text -demos/quickstart/protected/logs/logger.xml -text demos/quickstart/protected/pages/Configurations/AppConfig.page -text demos/quickstart/protected/pages/Configurations/Overview.page -text demos/quickstart/protected/pages/Configurations/PageConfig.page -text @@ -145,8 +144,7 @@ framework/Log/EventLog/writers/writer_database.php -text framework/Log/EventLog/writers/writer_file.php -text framework/Log/EventLog/writers/writer_unix_file.php -text framework/Log/TEventLog.php -text -framework/Log/TEzcLogger.php -text -framework/Log/TLog.php -text +framework/Log/TLogManager.php -text framework/Security/TAuthManager.php -text framework/Security/TAuthorizationRule.php -text framework/Security/TMembershipManager.php -text diff --git a/demos/quickstart/protected/application.xml b/demos/quickstart/protected/application.xml index d456bd89..d9ae0f44 100644 --- a/demos/quickstart/protected/application.xml +++ b/demos/quickstart/protected/application.xml @@ -2,18 +2,13 @@ - - - - + + + + diff --git a/demos/quickstart/protected/logs/logger.xml b/demos/quickstart/protected/logs/logger.xml deleted file mode 100644 index c02e135a..00000000 --- a/demos/quickstart/protected/logs/logger.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/framework/Collections/TList.php b/framework/Collections/TList.php index e9e143b2..232e39c6 100644 --- a/framework/Collections/TList.php +++ b/framework/Collections/TList.php @@ -84,6 +84,14 @@ class TList extends TComponent implements IteratorAggregate,ArrayAccess return $this->_c; } + /** + * @return integer the number of items in the list + */ + public function getLength() + { + return $this->getCount(); + } + /** * Returns the item at the specified offset. * This method is exactly the same as {@link offsetGet}. diff --git a/framework/Log/TEventLog.php b/framework/Log/TEventLog.php index d291d3f5..8fb56618 100644 --- a/framework/Log/TEventLog.php +++ b/framework/Log/TEventLog.php @@ -1,7 +1,7 @@ collectInternalLog(); + } + + public function __destruct() + { + $this->collectInternalLog(); + } + + protected function collectInternalLog() + { + foreach(Prado::coreLog()->entries as $entry) + $this->log($entry[0], $entry[1], $entry[2]); + Prado::coreLog()->entries = array(); + } public function info($msg, $source='Prado', $category='main') { - ezcLog::getInstance()->log($msg, ezcLog::INFO, + $this->log($msg, ezcLog::INFO, array('source'=>$source, 'category'=>$category)); } public function debug($msg, $source='Prado', $category='main') { - ezcLog::getInstance()->log($msg, ezcLog::DEBUG, + $this->log($msg, ezcLog::DEBUG, array('source'=>$source, 'category'=>$category)); } public function notice($msg, $source='Prado', $category='main') { - ezcLog::getInstance()->log($msg, ezcLog::NOTICE, + $this->log($msg, ezcLog::NOTICE, array('source'=>$source, 'category'=>$category)); } public function warn($msg, $source='Prado', $category='main') { - ezcLog::getInstance()->log($msg, ezcLog::WARNING, + $this->log($msg, ezcLog::WARNING, array('source'=>$source, 'category'=>$category)); } public function error($msg, $source='Prado', $category='main') { - ezcLog::getInstance()->log($msg, ezcLog::NOTICE, + $this->log($msg, ezcLog::NOTICE, array('source'=>$source, 'category'=>$category)); } public function fatal($msg, $source='Prado', $category='main') { - ezcLog::getInstance()->log($msg, ezcLog::NOTICE, + $this->log($msg, ezcLog::NOTICE, array('source'=>$source, 'category'=>$category)); } + + protected function log($msg, $code, $info) + { + ezcLog::getInstance()->log($msg, $code, $info); + } } ?> \ No newline at end of file diff --git a/framework/Log/TEzcLogger.php b/framework/Log/TEzcLogger.php deleted file mode 100644 index 11fe6c7f..00000000 --- a/framework/Log/TEzcLogger.php +++ /dev/null @@ -1,133 +0,0 @@ -config)) - $this->initLogger($this->loadConfigFromFile($this->config)); - else - $this->initLogger($xml); - } - - protected function loadConfigFromFile($file) - { - $xml = new TXmlDocument(); - $xml->loadFromFile($file); - return $xml->getElementByTagName('loggers'); - } - - protected function initLogger($xml) - { - TEzcLoggerLoader::using('ezcLog'); - TEzcLoggerLoader::using('ezcLogMap'); - TEzcLoggerLoader::using('ezcLogContext'); - TEzcLoggerLoader::using('ezcLogFilter'); - $loggers = $xml->getElementsByTagName('logger'); - $log = ezcLog::getInstance(); - foreach($loggers as $logger) - { - $filters = $logger->getElementsByTagName('filter'); - $logWriter = $this->getLogWriter($logger); - foreach($filters as $filter) - { - $logFilter = new ezcLogFilter(); - $Severity = $filter->getAttribute('severity'); - $logFilter->severity = $this->getFilterSeverity($Severity); - $map = $filter->getAttribute('disabled') ? 'unmap' : 'map'; - $log->$map($logFilter, $logWriter); - } - } - } - - protected function getLogWriter($xml) - { - switch($xml->getAttribute('destination')) - { - case 'file' : - return TEzcLoggerUnixFileWriterFactory::create($xml); - default : - throw new TException('invalid_log_destination'); - } - } - - protected function getFilterSeverity($string) - { - if(empty($string)) - $string = $this->defaultServerity; - $serverities = explode("|", $string); - $mask = 0; - foreach($serverities as $Severity) - $mask = $mask | $this->getSeverity($Severity); - return $mask; - } - - private function getSeverity($string) - { - switch(strtolower(trim($string))) - { - case 'debug': return ezcLog::DEBUG; - case 'success audit' : return ezcLog::SUCCESS_AUDIT; - case 'failed audit' : return ezcLog::FAILED_AUDIT; - case 'info' : return ezcLog::INFO; - case 'notice' : return ezcLog::NOTICE; - case 'warn' : return ezcLog::WARNING; - case 'error' : return ezcLog::ERROR; - case 'fatal' : return ezcLog::FATAL; - } - return 0; - } -} - - -/** - * ${classname} - * - * ${description} - * - * @author Wei Zhuo - * @version $Revision: 1.66 $ $Date: ${DATE} ${TIME} $ - * @package ${package} - */ -class TEzcLoggerUnixFileWriterFactory -{ - public static function create($xml) - { - TEzcLoggerLoader::using('ezcLogWriter'); - TEzcLoggerLoader::using('ezcLogWriterFile'); - TEzcLoggerLoader::using('ezcLogWriterUnixFile'); - - $dir = $xml->getAttribute('directory'); - $file = $xml->getAttribute('filename'); - if(empty($file)) $file = 'prado.log'; - return new ezcLogWriterUnixFile($dir, $file); - } -} - -/** - * ${classname} - * - * ${description} - * - * @author Wei Zhuo - * @version $Revision: 1.66 $ $Date: ${DATE} ${TIME} $ - * @package ${package} - */ -class TEzcLoggerLoader -{ - public static function using($class) - { - if(class_exists($class, false)) return; - static $classes; - $base = dirname(__FILE__); - if(is_null($classes)) - $classes = include($base.'/EventLog/log_autoload.php'); - require_once($base.'/'.$classes[$class]); - } -} - -?> \ No newline at end of file diff --git a/framework/Log/TLog.php b/framework/Log/TLog.php deleted file mode 100644 index 0a455c84..00000000 --- a/framework/Log/TLog.php +++ /dev/null @@ -1,13 +0,0 @@ - \ No newline at end of file diff --git a/framework/Log/TLogManager.php b/framework/Log/TLogManager.php new file mode 100644 index 00000000..dba96e3a --- /dev/null +++ b/framework/Log/TLogManager.php @@ -0,0 +1,141 @@ +config)) + $this->initLogger($this->loadConfigFromFile($this->config)); + else + $this->initLogger($xml); + } + + protected function loadConfigFromFile($file) + { + $xml = new TXmlDocument(); + $xml->loadFromFile($file); + return $xml->getElementByTagName('loggers'); + } + + protected function initLogger($xml) + { + TEzcLoggerLoader::using('ezcLog'); + TEzcLoggerLoader::using('ezcLogMap'); + TEzcLoggerLoader::using('ezcLogContext'); + TEzcLoggerLoader::using('ezcLogFilter'); + + $log = ezcLog::getInstance(); + foreach($xml->getElementsByTagName('logger') as $logger) + { + $logWriter = $this->getLogWriter($logger); + $filters = $logger->getElementsByTagName('filter'); + foreach($filters as $filter) + { + $logFilter = new ezcLogFilter(); + $Severity = $filter->getAttribute('severity'); + $logFilter->severity = $this->getFilterSeverity($Severity); + $map = $filter->getAttribute('disabled') ? 'unmap' : 'map'; + $log->$map($logFilter, $logWriter); + } + + if($filters->Length < 1) + { + $logFilter = new ezcLogFilter(); + $logFilter->severity = $this->getFilterSeverity(); + $log->map($logFilter, $logWriter); + } + } + } + + protected function getLogWriter($xml) + { + switch($xml->getAttribute('destination')) + { + case 'file' : + return TEzcLoggerUnixFileWriterFactory::create($xml); + default : + throw new TException('invalid_log_destination'); + } + } + + protected function getFilterSeverity($string='') + { + if(empty($string)) + $string = $this->defaultSeverity; + $serverities = explode("|", $string); + $mask = 0; + foreach($serverities as $Severity) + $mask = $mask | $this->getSeverity($Severity); + return $mask; + } + + private function getSeverity($string) + { + switch(strtolower(trim($string))) + { + case 'debug': return ezcLog::DEBUG; + case 'success audit' : return ezcLog::SUCCESS_AUDIT; + case 'failed audit' : return ezcLog::FAILED_AUDIT; + case 'info' : return ezcLog::INFO; + case 'notice' : return ezcLog::NOTICE; + case 'warn' : return ezcLog::WARNING; + case 'error' : return ezcLog::ERROR; + case 'fatal' : return ezcLog::FATAL; + } + return 0; + } +} + + +/** + * ${classname} + * + * ${description} + * + * @author Wei Zhuo + * @version $Revision: 1.66 $ $Date: ${DATE} ${TIME} $ + * @package ${package} + */ +class TEzcLoggerUnixFileWriterFactory +{ + public static function create($xml) + { + TEzcLoggerLoader::using('ezcLogWriter'); + TEzcLoggerLoader::using('ezcLogWriterFile'); + TEzcLoggerLoader::using('ezcLogWriterUnixFile'); + + $path = $xml->getAttribute('directory'); + $dir = Prado::getPathOfNamespace($path); + $file = $xml->getAttribute('filename'); + if(empty($file)) $file = 'prado.log'; + return new ezcLogWriterUnixFile($dir, $file); + } +} + +/** + * ${classname} + * + * ${description} + * + * @author Wei Zhuo + * @version $Revision: 1.66 $ $Date: ${DATE} ${TIME} $ + * @package ${package} + */ +class TEzcLoggerLoader +{ + public static function using($class) + { + if(class_exists($class, false)) return; + static $classes; + $base = dirname(__FILE__); + if(is_null($classes)) + $classes = include($base.'/EventLog/log_autoload.php'); + require_once($base.'/'.$classes[$class]); + } +} + +?> \ No newline at end of file diff --git a/framework/TApplication.php b/framework/TApplication.php index 60fc25b3..0e808858 100644 --- a/framework/TApplication.php +++ b/framework/TApplication.php @@ -35,6 +35,7 @@ require_once(PRADO_DIR.'/Security/TAuthorizationRule.php'); */ require_once(PRADO_DIR.'/Web/Services/TPageService.php'); + /** * TApplication class. * @@ -301,6 +302,7 @@ class TApplication extends TComponent if($this->_mode===self::STATE_OFF) throw new THttpException(503,'application_service_unavailable'); $method='on'.self::$_steps[$this->_step]; + Prado::coreLog("Executing $method"); $this->$method($this); if($this->_requestCompleted && $this->_step<$n-1) $this->_step=$n-1; @@ -709,6 +711,7 @@ class TApplication extends TComponent */ protected function initApplication() { + Prado::coreLog("Initializing application"); Prado::setPathOfAlias('Application',$this->_basePath); if($this->_configFile===null) @@ -730,7 +733,7 @@ class TApplication extends TComponent fclose($fp); } else - syslog(LOG_WARNING,'Prado application config cache file "'.$this->_cacheFile.'" cannot be created.'); + syslog(LOG_WARNING, 'Prado application config cache file "'.$this->_cacheFile.'" cannot be created.'); } } else @@ -767,6 +770,7 @@ class TApplication extends TComponent $this->_modules=array(); foreach($config->getModules() as $id=>$moduleConfig) { + Prado::coreLog("Creating module $id"); $module=Prado::createComponent($moduleConfig[0]); $this->_modules[$id]=$module; foreach($moduleConfig[1] as $name=>$value) diff --git a/framework/Web/Services/TPageService.php b/framework/Web/Services/TPageService.php index 5723269f..8f12c650 100644 --- a/framework/Web/Services/TPageService.php +++ b/framework/Web/Services/TPageService.php @@ -146,6 +146,7 @@ class TPageService extends TService */ public function init($config) { + Prado::coreLog("Initializing TPageService"); $application=$this->getApplication(); $application->setPageService($this); @@ -250,6 +251,7 @@ class TPageService extends TService // load modules specified in page directory config foreach($pageConfig->getModules() as $id=>$moduleConfig) { + Prado::coreLog("Loading module $id"); $module=Prado::createComponent($moduleConfig[0]); $application->setModule($id,$module); foreach($moduleConfig[1] as $name=>$value) @@ -425,6 +427,7 @@ class TPageService extends TService */ public function run() { + Prado::coreLog("Running page service"); $page=null; $path=$this->_basePath.'/'.strtr($this->_pagePath,'.','/'); if(is_file($path.self::PAGE_FILE_EXT)) @@ -611,6 +614,7 @@ class TPageConfiguration extends TComponent */ private function loadFromFile($fname,$page) { + Prado::coreLog("Loading $page with file $fname"); if(empty($fname) || !is_file($fname)) return; $dom=new TXmlDocument; diff --git a/framework/Web/THttpRequest.php b/framework/Web/THttpRequest.php index c3c9e33d..bb2eb7b4 100644 --- a/framework/Web/THttpRequest.php +++ b/framework/Web/THttpRequest.php @@ -373,6 +373,7 @@ class THttpRequest extends TModule break; } } + Prado::coreLog("Resolving request {$this->_serviceID}={$this->_serviceParam}"); } /** diff --git a/framework/Web/THttpResponse.php b/framework/Web/THttpResponse.php index ba2f607c..ecaf59d0 100644 --- a/framework/Web/THttpResponse.php +++ b/framework/Web/THttpResponse.php @@ -232,6 +232,7 @@ class THttpResponse extends TModule implements ITextWriter { if($this->_bufferOutput) ob_flush(); + Prado::coreLog("Flushing output"); } /** @@ -241,6 +242,7 @@ class THttpResponse extends TModule implements ITextWriter { if($this->_bufferOutput) ob_clean(); + Prado::coreLog("Clearing output"); } /** diff --git a/framework/Web/UI/TAssetManager.php b/framework/Web/UI/TAssetManager.php index 0cce2c27..1ff0f47a 100644 --- a/framework/Web/UI/TAssetManager.php +++ b/framework/Web/UI/TAssetManager.php @@ -141,6 +141,7 @@ class TAssetManager extends TModule */ public function publishFilePath($path,$checkTimestamp=false) { + Prado::coreLog("Publishing file $path"); if(isset($this->_published[$path])) return $this->_published[$path]; else if(($fullpath=realpath($path))===false) diff --git a/framework/Web/UI/TControl.php b/framework/Web/UI/TControl.php index 34e9b92f..3ba79478 100644 --- a/framework/Web/UI/TControl.php +++ b/framework/Web/UI/TControl.php @@ -683,8 +683,11 @@ class TControl extends TComponent */ public function dataBind() { + Prado::coreLog("Data bind properties"); $this->dataBindProperties(); + Prado::coreLog("onDataBinding()"); $this->onDataBinding(null); + Prado::coreLog("dataBindChildren()"); $this->dataBindChildren(); } diff --git a/framework/Web/UI/TForm.php b/framework/Web/UI/TForm.php index 4cb97911..28c6c3aa 100644 --- a/framework/Web/UI/TForm.php +++ b/framework/Web/UI/TForm.php @@ -53,6 +53,7 @@ class TForm extends TControl */ protected function render($writer) { + Prado::coreLog("Rendering form ".$this->getName()); $this->addAttributesToRender($writer); $writer->renderBeginTag('form'); $page=$this->getPage(); diff --git a/framework/Web/UI/TPage.php b/framework/Web/UI/TPage.php index 624ed550..2269079b 100644 --- a/framework/Web/UI/TPage.php +++ b/framework/Web/UI/TPage.php @@ -133,38 +133,59 @@ class TPage extends TTemplateControl */ public function run($writer) { + Prado::coreLog("Running page life cycles"); $this->determinePostBackMode(); - + + Prado::coreLog("Page onPreInit()"); $this->onPreInit(null); + Prado::coreLog("Page initRecursive()"); $this->initRecursive(); + Prado::coreLog("Page onInitComplete()"); $this->onInitComplete(null); if($this->getIsPostBack()) { $this->_restPostData=new TMap; + Prado::coreLog("Page loadPageState()"); $this->loadPageState(); + Prado::coreLog("Page processPostData()"); $this->processPostData($this->_postData,true); + Prado::coreLog("Page onPreLoad()"); $this->onPreLoad(null); + Prado::coreLog("Page loadRecursive()"); $this->loadRecursive(); + Prado::coreLog("Page processPostData()"); $this->processPostData($this->_restPostData,false); + Prado::coreLog("Page raiseChangedEvents()"); $this->raiseChangedEvents(); + Prado::coreLog("Page raisePostBackEvent()"); $this->raisePostBackEvent(); + Prado::coreLog("Page onLoadComplete()"); $this->onLoadComplete(null); } else { + Prado::coreLog("Page onPreLoad()"); $this->onPreLoad(null); + Prado::coreLog("Page loadRecursive()"); $this->loadRecursive(); + Prado::coreLog("Page onLoadComplete()"); $this->onLoadComplete(null); } + Prado::coreLog("Page preRenderRecursive()"); $this->preRenderRecursive(); + Prado::coreLog("Page onPreRenderComplete()"); $this->onPreRenderComplete(null); + Prado::coreLog("Page savePageState()"); $this->savePageState(); + Prado::coreLog("Page onSaveStateComplete()"); $this->onSaveStateComplete(null); + Prado::coreLog("Page renderControl()"); $this->renderControl($writer); + Prado::coreLog("Page unloadRecursive()"); $this->unloadRecursive(); } @@ -263,6 +284,7 @@ class TPage extends TTemplateControl $this->_validated=true; if($this->_validators && $this->_validators->getCount()) { + Prado::coreLog("Page validate"); if($validationGroup==='') { foreach($this->_validators as $validator) diff --git a/framework/Web/UI/TPageStatePersister.php b/framework/Web/UI/TPageStatePersister.php index d312ed84..2711041a 100644 --- a/framework/Web/UI/TPageStatePersister.php +++ b/framework/Web/UI/TPageStatePersister.php @@ -52,6 +52,7 @@ class TPageStatePersister extends TModule implements IStatePersister */ public function save($state) { + Prado::coreLog("Saving state"); $data=Prado::serialize($state); $hmac=$this->computeHMAC($data,$this->getPrivateKey()); if(extension_loaded('zlib')) @@ -68,6 +69,7 @@ class TPageStatePersister extends TModule implements IStatePersister */ public function load() { + Prado::coreLog("Loading state"); $str=base64_decode($this->getApplication()->getRequest()->getItems()->itemAt(TPage::FIELD_PAGESTATE)); if($str==='') return null; diff --git a/framework/Web/UI/TTemplateControl.php b/framework/Web/UI/TTemplateControl.php index 9987bc9c..a25a2e41 100644 --- a/framework/Web/UI/TTemplateControl.php +++ b/framework/Web/UI/TTemplateControl.php @@ -101,8 +101,9 @@ class TTemplateControl extends TControl implements INamingContainer */ protected function loadTemplate() { + Prado::coreLog("Loading template ".get_class($this)); $template=$this->getService()->getTemplateManager()->getTemplateByClassName(get_class($this)); - self::$_template[get_class($this)]=$template; + self::$_template[get_class($this)]=$template; return $template; } diff --git a/framework/Web/UI/TThemeManager.php b/framework/Web/UI/TThemeManager.php index bbcd35a6..73745254 100644 --- a/framework/Web/UI/TThemeManager.php +++ b/framework/Web/UI/TThemeManager.php @@ -313,6 +313,7 @@ class TTheme extends TComponent { foreach($this->_skins[$type][$id] as $name=>$value) { + Prado::coreLog("Applying skin $name to $type"); if(is_array($value)) { if($value[0]===TTemplate::CONFIG_EXPRESSION) diff --git a/framework/core.php b/framework/core.php index 5c9156e5..b2ae1d45 100644 --- a/framework/core.php +++ b/framework/core.php @@ -42,6 +42,8 @@ require_once(PRADO_DIR.'/Data/TXmlDocument.php'); */ require_once(PRADO_DIR.'/Web/THttpUtility.php'); +require_once(PRADO_DIR.'/Log/ILog.php'); + /** * IModule interface. * @@ -770,6 +772,16 @@ class PradoBase } return $language; } + + public static function coreLog($msg=null) + { + static $logger; + if(is_null($logger)) + $logger = new TInternalLogger(); + if(!empty($msg)) + $logger->info($msg); + return $logger; + } } ?> \ No newline at end of file diff --git a/framework/prado.php b/framework/prado.php index ed6a4f49..844394f7 100644 --- a/framework/prado.php +++ b/framework/prado.php @@ -1,61 +1,61 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2005 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Revision: $ $Date: $ - * @package System - */ - -/** - * Includes the Prado core header file - */ -require_once(dirname(__FILE__).'/core.php'); - -/** - * Defines Prado class if not defined. - */ -if(!class_exists('Prado',false)) -{ - class Prado extends PradoBase - { - } -} - -/** - * Defines __autoload function if not defined. - */ -if(!function_exists('__autoload')) -{ - function __autoload($className) - { - include_once($className.Prado::CLASS_FILE_EXT); - if(!class_exists($className,false)) - Prado::fatalError("Class file for '$className' cannot be found."); - } -} - -/** - * Sets error handler to be Prado::phpErrorHandler - */ -set_error_handler(array('Prado','phpErrorHandler'),error_reporting()); -/** - * Sets exception handler to be Prado::exceptionHandler - */ -set_exception_handler(array('Prado','exceptionHandler')); - -/** - * Includes TApplication class file - */ -require_once(dirname(__FILE__).'/TApplication.php'); - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Revision: $ $Date: $ + * @package System + */ + +/** + * Includes the Prado core header file + */ +require_once(dirname(__FILE__).'/core.php'); + +/** + * Defines Prado class if not defined. + */ +if(!class_exists('Prado',false)) +{ + class Prado extends PradoBase + { + } +} + +/** + * Defines __autoload function if not defined. + */ +if(!function_exists('__autoload')) +{ + function __autoload($className) + { + include_once($className.Prado::CLASS_FILE_EXT); + if(!class_exists($className,false)) + Prado::fatalError("Class file for '$className' cannot be found."); + } +} + +/** + * Sets error handler to be Prado::phpErrorHandler + */ +set_error_handler(array('Prado','phpErrorHandler'),error_reporting()); +/** + * Sets exception handler to be Prado::exceptionHandler + */ +set_exception_handler(array('Prado','exceptionHandler')); + +/** + * Includes TApplication class file + */ +require_once(dirname(__FILE__).'/TApplication.php'); + ?> \ No newline at end of file diff --git a/tools/phpbuilder/build.php b/tools/phpbuilder/build.php index a96ab12f..24626b85 100644 --- a/tools/phpbuilder/build.php +++ b/tools/phpbuilder/build.php @@ -42,14 +42,58 @@ foreach($lines as $line) continue; echo 'adding '.FRAMEWORK_DIR.'/'.$line."\n"; $input=file_get_contents(FRAMEWORK_DIR.'/'.$line); - $input=strtr($input,"\r",''); - $input=preg_replace('/\/\*.*?\*\//s','',$input); - $input=preg_replace('/^Prado::using\([^\*]*?\);/m','',$input); - $input=preg_replace('/^(require|require_once)\s*\(.*?;/m','',$input); - $input=preg_replace('/^(include|include_once)\s*\(.*?;/m','',$input); + $input = strip_comments($input); + $input=strtr($input,"\r",' '); + $input=preg_replace("/\s*(\n+\s*){2,}\s*/m","\n",$input); + $input=preg_replace('/^Prado::using\([^\*]*?\);/mu','',$input); + $input=preg_replace('/^(require|require_once)\s*\(.*?;/mu','',$input); + $input=preg_replace('/^(include|include_once)\s*\(.*?;/mu','',$input); + + //remove internal logging + $input=preg_replace('/^\s*Prado::coreLog.*\s*;\s*$/mu','',$input); + $output.=$input; } file_put_contents(FRAMEWORK_DIR.'/'.OUTPUT_FILE,$output); +function strip_comments($source) +{ + $tokens = token_get_all($source); + /* T_ML_COMMENT does not exist in PHP 5. + * The following three lines define it in order to + * preserve backwards compatibility. + * + * The next two lines define the PHP 5-only T_DOC_COMMENT, + * which we will mask as T_ML_COMMENT for PHP 4. + */ + if (!defined('T_ML_COMMENT')) { + @define('T_ML_COMMENT', T_COMMENT); + } else { + @define('T_DOC_COMMENT', T_ML_COMMENT); + } + $output = ''; + foreach ($tokens as $token) { + if (is_string($token)) { + // simple 1-character token + $output .= $token; + } else { + // token array + list($id, $text) = $token; + switch ($id) { + case T_COMMENT: + case T_ML_COMMENT: // we've defined this + case T_DOC_COMMENT: // and this + // no action on comments + break; + default: + // anything else -> output "as is" + $output .= $text; + break; + } + } + } + return $output; +} + ?> \ No newline at end of file diff --git a/tools/phpbuilder/files.txt b/tools/phpbuilder/files.txt index 22218685..011259de 100644 --- a/tools/phpbuilder/files.txt +++ b/tools/phpbuilder/files.txt @@ -16,7 +16,7 @@ Web/Services/TPageService.php Web/UI/TTemplateManager.php Web/UI/TThemeManager.php Web/UI/TAssetManager.php -Web/UI/THiddenFieldPageStatePersister.php +Web/UI/TPageStatePersister.php Web/UI/TControl.php Web/UI/TTemplateControl.php Web/UI/TForm.php -- cgit v1.2.3