/yii/framework/yiilite.php
PHP | 10023 lines | 9966 code | 2 blank | 55 comment | 707 complexity | 9f23d140de371469908a3c3fab54062e MD5 | raw file
Possible License(s): GPL-3.0, BSD-3-Clause, LGPL-3.0, LGPL-2.1, BSD-2-Clause, GPL-2.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- * Yii bootstrap file.
- *
- * This file is automatically generated using 'build lite' command.
- * It is the result of merging commonly used Yii class files with
- * comments and trace statements removed away.
- *
- * By using this file instead of yii.php, an Yii application may
- * improve performance due to the reduction of PHP parsing time.
- * The performance improvement is especially obvious when PHP APC extension
- * is enabled.
- *
- * DO NOT modify this file manually.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.yiiframework.com/
- * @copyright Copyright © 2008-2012 Yii Software LLC
- * @license http://www.yiiframework.com/license/
- * @version $Id: $
- * @since 1.0
- */
- defined('YII_BEGIN_TIME') or define('YII_BEGIN_TIME',microtime(true));
- defined('YII_DEBUG') or define('YII_DEBUG',false);
- defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',0);
- defined('YII_ENABLE_EXCEPTION_HANDLER') or define('YII_ENABLE_EXCEPTION_HANDLER',true);
- defined('YII_ENABLE_ERROR_HANDLER') or define('YII_ENABLE_ERROR_HANDLER',true);
- defined('YII_PATH') or define('YII_PATH',dirname(__FILE__));
- defined('YII_ZII_PATH') or define('YII_ZII_PATH',YII_PATH.DIRECTORY_SEPARATOR.'zii');
- class YiiBase
- {
- public static $classMap=array();
- public static $enableIncludePath=true;
- private static $_aliases=array('system'=>YII_PATH,'zii'=>YII_ZII_PATH); // alias => path
- private static $_imports=array(); // alias => class name or directory
- private static $_includePaths; // list of include paths
- private static $_app;
- private static $_logger;
- public static function getVersion()
- {
- return '1.1.13';
- }
- public static function createWebApplication($config=null)
- {
- return self::createApplication('CWebApplication',$config);
- }
- public static function createConsoleApplication($config=null)
- {
- return self::createApplication('CConsoleApplication',$config);
- }
- public static function createApplication($class,$config=null)
- {
- return new $class($config);
- }
- public static function app()
- {
- return self::$_app;
- }
- public static function setApplication($app)
- {
- if(self::$_app===null || $app===null)
- self::$_app=$app;
- else
- throw new CException(Yii::t('yii','Yii application can only be created once.'));
- }
- public static function getFrameworkPath()
- {
- return YII_PATH;
- }
- public static function createComponent($config)
- {
- if(is_string($config))
- {
- $type=$config;
- $config=array();
- }
- elseif(isset($config['class']))
- {
- $type=$config['class'];
- unset($config['class']);
- }
- else
- throw new CException(Yii::t('yii','Object configuration must be an array containing a "class" element.'));
- if(!class_exists($type,false))
- $type=Yii::import($type,true);
- if(($n=func_num_args())>1)
- {
- $args=func_get_args();
- if($n===2)
- $object=new $type($args[1]);
- elseif($n===3)
- $object=new $type($args[1],$args[2]);
- elseif($n===4)
- $object=new $type($args[1],$args[2],$args[3]);
- else
- {
- unset($args[0]);
- $class=new ReflectionClass($type);
- // Note: ReflectionClass::newInstanceArgs() is available for PHP 5.1.3+
- // $object=$class->newInstanceArgs($args);
- $object=call_user_func_array(array($class,'newInstance'),$args);
- }
- }
- else
- $object=new $type;
- foreach($config as $key=>$value)
- $object->$key=$value;
- return $object;
- }
- public static function import($alias,$forceInclude=false)
- {
- if(isset(self::$_imports[$alias])) // previously imported
- return self::$_imports[$alias];
- if(class_exists($alias,false) || interface_exists($alias,false))
- return self::$_imports[$alias]=$alias;
- if(($pos=strrpos($alias,'\\'))!==false) // a class name in PHP 5.3 namespace format
- {
- $namespace=str_replace('\\','.',ltrim(substr($alias,0,$pos),'\\'));
- if(($path=self::getPathOfAlias($namespace))!==false)
- {
- $classFile=$path.DIRECTORY_SEPARATOR.substr($alias,$pos+1).'.php';
- if($forceInclude)
- {
- if(is_file($classFile))
- require($classFile);
- else
- throw new CException(Yii::t('yii','Alias "{alias}" is invalid. Make sure it points to an existing PHP file and the file is readable.',array('{alias}'=>$alias)));
- self::$_imports[$alias]=$alias;
- }
- else
- self::$classMap[$alias]=$classFile;
- return $alias;
- }
- else
- throw new CException(Yii::t('yii','Alias "{alias}" is invalid. Make sure it points to an existing directory.',
- array('{alias}'=>$namespace)));
- }
- if(($pos=strrpos($alias,'.'))===false) // a simple class name
- {
- if($forceInclude && self::autoload($alias))
- self::$_imports[$alias]=$alias;
- return $alias;
- }
- $className=(string)substr($alias,$pos+1);
- $isClass=$className!=='*';
- if($isClass && (class_exists($className,false) || interface_exists($className,false)))
- return self::$_imports[$alias]=$className;
- if(($path=self::getPathOfAlias($alias))!==false)
- {
- if($isClass)
- {
- if($forceInclude)
- {
- if(is_file($path.'.php'))
- require($path.'.php');
- else
- throw new CException(Yii::t('yii','Alias "{alias}" is invalid. Make sure it points to an existing PHP file and the file is readable.',array('{alias}'=>$alias)));
- self::$_imports[$alias]=$className;
- }
- else
- self::$classMap[$className]=$path.'.php';
- return $className;
- }
- else // a directory
- {
- if(self::$_includePaths===null)
- {
- self::$_includePaths=array_unique(explode(PATH_SEPARATOR,get_include_path()));
- if(($pos=array_search('.',self::$_includePaths,true))!==false)
- unset(self::$_includePaths[$pos]);
- }
- array_unshift(self::$_includePaths,$path);
- if(self::$enableIncludePath && set_include_path('.'.PATH_SEPARATOR.implode(PATH_SEPARATOR,self::$_includePaths))===false)
- self::$enableIncludePath=false;
- return self::$_imports[$alias]=$path;
- }
- }
- else
- throw new CException(Yii::t('yii','Alias "{alias}" is invalid. Make sure it points to an existing directory or file.',
- array('{alias}'=>$alias)));
- }
- public static function getPathOfAlias($alias)
- {
- if(isset(self::$_aliases[$alias]))
- return self::$_aliases[$alias];
- elseif(($pos=strpos($alias,'.'))!==false)
- {
- $rootAlias=substr($alias,0,$pos);
- if(isset(self::$_aliases[$rootAlias]))
- return self::$_aliases[$alias]=rtrim(self::$_aliases[$rootAlias].DIRECTORY_SEPARATOR.str_replace('.',DIRECTORY_SEPARATOR,substr($alias,$pos+1)),'*'.DIRECTORY_SEPARATOR);
- elseif(self::$_app instanceof CWebApplication)
- {
- if(self::$_app->findModule($rootAlias)!==null)
- return self::getPathOfAlias($alias);
- }
- }
- return false;
- }
- public static function setPathOfAlias($alias,$path)
- {
- if(empty($path))
- unset(self::$_aliases[$alias]);
- else
- self::$_aliases[$alias]=rtrim($path,'\\/');
- }
- public static function autoload($className)
- {
- // use include so that the error PHP file may appear
- if(isset(self::$classMap[$className]))
- include(self::$classMap[$className]);
- elseif(isset(self::$_coreClasses[$className]))
- include(YII_PATH.self::$_coreClasses[$className]);
- else
- {
- // include class file relying on include_path
- if(strpos($className,'\\')===false) // class without namespace
- {
- if(self::$enableIncludePath===false)
- {
- foreach(self::$_includePaths as $path)
- {
- $classFile=$path.DIRECTORY_SEPARATOR.$className.'.php';
- if(is_file($classFile))
- {
- include($classFile);
- if(YII_DEBUG && basename(realpath($classFile))!==$className.'.php')
- throw new CException(Yii::t('yii','Class name "{class}" does not match class file "{file}".', array(
- '{class}'=>$className,
- '{file}'=>$classFile,
- )));
- break;
- }
- }
- }
- else
- include($className.'.php');
- }
- else // class name with namespace in PHP 5.3
- {
- $namespace=str_replace('\\','.',ltrim($className,'\\'));
- if(($path=self::getPathOfAlias($namespace))!==false)
- include($path.'.php');
- else
- return false;
- }
- return class_exists($className,false) || interface_exists($className,false);
- }
- return true;
- }
- public static function trace($msg,$category='application')
- {
- if(YII_DEBUG)
- self::log($msg,CLogger::LEVEL_TRACE,$category);
- }
- public static function log($msg,$level=CLogger::LEVEL_INFO,$category='application')
- {
- if(self::$_logger===null)
- self::$_logger=new CLogger;
- if(YII_DEBUG && YII_TRACE_LEVEL>0 && $level!==CLogger::LEVEL_PROFILE)
- {
- $traces=debug_backtrace();
- $count=0;
- foreach($traces as $trace)
- {
- if(isset($trace['file'],$trace['line']) && strpos($trace['file'],YII_PATH)!==0)
- {
- $msg.="\nin ".$trace['file'].' ('.$trace['line'].')';
- if(++$count>=YII_TRACE_LEVEL)
- break;
- }
- }
- }
- self::$_logger->log($msg,$level,$category);
- }
- public static function beginProfile($token,$category='application')
- {
- self::log('begin:'.$token,CLogger::LEVEL_PROFILE,$category);
- }
- public static function endProfile($token,$category='application')
- {
- self::log('end:'.$token,CLogger::LEVEL_PROFILE,$category);
- }
- public static function getLogger()
- {
- if(self::$_logger!==null)
- return self::$_logger;
- else
- return self::$_logger=new CLogger;
- }
- public static function setLogger($logger)
- {
- self::$_logger=$logger;
- }
- public static function powered()
- {
- return Yii::t('yii','Powered by {yii}.', array('{yii}'=>'<a href="http://www.yiiframework.com/" rel="external">Yii Framework</a>'));
- }
- public static function t($category,$message,$params=array(),$source=null,$language=null)
- {
- if(self::$_app!==null)
- {
- if($source===null)
- $source=($category==='yii'||$category==='zii')?'coreMessages':'messages';
- if(($source=self::$_app->getComponent($source))!==null)
- $message=$source->translate($category,$message,$language);
- }
- if($params===array())
- return $message;
- if(!is_array($params))
- $params=array($params);
- if(isset($params[0])) // number choice
- {
- if(strpos($message,'|')!==false)
- {
- if(strpos($message,'#')===false)
- {
- $chunks=explode('|',$message);
- $expressions=self::$_app->getLocale($language)->getPluralRules();
- if($n=min(count($chunks),count($expressions)))
- {
- for($i=0;$i<$n;$i++)
- $chunks[$i]=$expressions[$i].'#'.$chunks[$i];
- $message=implode('|',$chunks);
- }
- }
- $message=CChoiceFormat::format($message,$params[0]);
- }
- if(!isset($params['{n}']))
- $params['{n}']=$params[0];
- unset($params[0]);
- }
- return $params!==array() ? strtr($message,$params) : $message;
- }
- public static function registerAutoloader($callback, $append=false)
- {
- if($append)
- {
- self::$enableIncludePath=false;
- spl_autoload_register($callback);
- }
- else
- {
- spl_autoload_unregister(array('YiiBase','autoload'));
- spl_autoload_register($callback);
- spl_autoload_register(array('YiiBase','autoload'));
- }
- }
- private static $_coreClasses=array(
- 'CApplication' => '/base/CApplication.php',
- 'CApplicationComponent' => '/base/CApplicationComponent.php',
- 'CBehavior' => '/base/CBehavior.php',
- 'CComponent' => '/base/CComponent.php',
- 'CErrorEvent' => '/base/CErrorEvent.php',
- 'CErrorHandler' => '/base/CErrorHandler.php',
- 'CException' => '/base/CException.php',
- 'CExceptionEvent' => '/base/CExceptionEvent.php',
- 'CHttpException' => '/base/CHttpException.php',
- 'CModel' => '/base/CModel.php',
- 'CModelBehavior' => '/base/CModelBehavior.php',
- 'CModelEvent' => '/base/CModelEvent.php',
- 'CModule' => '/base/CModule.php',
- 'CSecurityManager' => '/base/CSecurityManager.php',
- 'CStatePersister' => '/base/CStatePersister.php',
- 'CApcCache' => '/caching/CApcCache.php',
- 'CCache' => '/caching/CCache.php',
- 'CDbCache' => '/caching/CDbCache.php',
- 'CDummyCache' => '/caching/CDummyCache.php',
- 'CEAcceleratorCache' => '/caching/CEAcceleratorCache.php',
- 'CFileCache' => '/caching/CFileCache.php',
- 'CMemCache' => '/caching/CMemCache.php',
- 'CWinCache' => '/caching/CWinCache.php',
- 'CXCache' => '/caching/CXCache.php',
- 'CZendDataCache' => '/caching/CZendDataCache.php',
- 'CCacheDependency' => '/caching/dependencies/CCacheDependency.php',
- 'CChainedCacheDependency' => '/caching/dependencies/CChainedCacheDependency.php',
- 'CDbCacheDependency' => '/caching/dependencies/CDbCacheDependency.php',
- 'CDirectoryCacheDependency' => '/caching/dependencies/CDirectoryCacheDependency.php',
- 'CExpressionDependency' => '/caching/dependencies/CExpressionDependency.php',
- 'CFileCacheDependency' => '/caching/dependencies/CFileCacheDependency.php',
- 'CGlobalStateCacheDependency' => '/caching/dependencies/CGlobalStateCacheDependency.php',
- 'CAttributeCollection' => '/collections/CAttributeCollection.php',
- 'CConfiguration' => '/collections/CConfiguration.php',
- 'CList' => '/collections/CList.php',
- 'CListIterator' => '/collections/CListIterator.php',
- 'CMap' => '/collections/CMap.php',
- 'CMapIterator' => '/collections/CMapIterator.php',
- 'CQueue' => '/collections/CQueue.php',
- 'CQueueIterator' => '/collections/CQueueIterator.php',
- 'CStack' => '/collections/CStack.php',
- 'CStackIterator' => '/collections/CStackIterator.php',
- 'CTypedList' => '/collections/CTypedList.php',
- 'CTypedMap' => '/collections/CTypedMap.php',
- 'CConsoleApplication' => '/console/CConsoleApplication.php',
- 'CConsoleCommand' => '/console/CConsoleCommand.php',
- 'CConsoleCommandBehavior' => '/console/CConsoleCommandBehavior.php',
- 'CConsoleCommandEvent' => '/console/CConsoleCommandEvent.php',
- 'CConsoleCommandRunner' => '/console/CConsoleCommandRunner.php',
- 'CHelpCommand' => '/console/CHelpCommand.php',
- 'CDbCommand' => '/db/CDbCommand.php',
- 'CDbConnection' => '/db/CDbConnection.php',
- 'CDbDataReader' => '/db/CDbDataReader.php',
- 'CDbException' => '/db/CDbException.php',
- 'CDbMigration' => '/db/CDbMigration.php',
- 'CDbTransaction' => '/db/CDbTransaction.php',
- 'CActiveFinder' => '/db/ar/CActiveFinder.php',
- 'CActiveRecord' => '/db/ar/CActiveRecord.php',
- 'CActiveRecordBehavior' => '/db/ar/CActiveRecordBehavior.php',
- 'CDbColumnSchema' => '/db/schema/CDbColumnSchema.php',
- 'CDbCommandBuilder' => '/db/schema/CDbCommandBuilder.php',
- 'CDbCriteria' => '/db/schema/CDbCriteria.php',
- 'CDbExpression' => '/db/schema/CDbExpression.php',
- 'CDbSchema' => '/db/schema/CDbSchema.php',
- 'CDbTableSchema' => '/db/schema/CDbTableSchema.php',
- 'CMssqlColumnSchema' => '/db/schema/mssql/CMssqlColumnSchema.php',
- 'CMssqlCommandBuilder' => '/db/schema/mssql/CMssqlCommandBuilder.php',
- 'CMssqlPdoAdapter' => '/db/schema/mssql/CMssqlPdoAdapter.php',
- 'CMssqlSchema' => '/db/schema/mssql/CMssqlSchema.php',
- 'CMssqlSqlsrvPdoAdapter' => '/db/schema/mssql/CMssqlSqlsrvPdoAdapter.php',
- 'CMssqlTableSchema' => '/db/schema/mssql/CMssqlTableSchema.php',
- 'CMysqlColumnSchema' => '/db/schema/mysql/CMysqlColumnSchema.php',
- 'CMysqlCommandBuilder' => '/db/schema/mysql/CMysqlCommandBuilder.php',
- 'CMysqlSchema' => '/db/schema/mysql/CMysqlSchema.php',
- 'CMysqlTableSchema' => '/db/schema/mysql/CMysqlTableSchema.php',
- 'COciColumnSchema' => '/db/schema/oci/COciColumnSchema.php',
- 'COciCommandBuilder' => '/db/schema/oci/COciCommandBuilder.php',
- 'COciSchema' => '/db/schema/oci/COciSchema.php',
- 'COciTableSchema' => '/db/schema/oci/COciTableSchema.php',
- 'CPgsqlColumnSchema' => '/db/schema/pgsql/CPgsqlColumnSchema.php',
- 'CPgsqlSchema' => '/db/schema/pgsql/CPgsqlSchema.php',
- 'CPgsqlTableSchema' => '/db/schema/pgsql/CPgsqlTableSchema.php',
- 'CSqliteColumnSchema' => '/db/schema/sqlite/CSqliteColumnSchema.php',
- 'CSqliteCommandBuilder' => '/db/schema/sqlite/CSqliteCommandBuilder.php',
- 'CSqliteSchema' => '/db/schema/sqlite/CSqliteSchema.php',
- 'CChoiceFormat' => '/i18n/CChoiceFormat.php',
- 'CDateFormatter' => '/i18n/CDateFormatter.php',
- 'CDbMessageSource' => '/i18n/CDbMessageSource.php',
- 'CGettextMessageSource' => '/i18n/CGettextMessageSource.php',
- 'CLocale' => '/i18n/CLocale.php',
- 'CMessageSource' => '/i18n/CMessageSource.php',
- 'CNumberFormatter' => '/i18n/CNumberFormatter.php',
- 'CPhpMessageSource' => '/i18n/CPhpMessageSource.php',
- 'CGettextFile' => '/i18n/gettext/CGettextFile.php',
- 'CGettextMoFile' => '/i18n/gettext/CGettextMoFile.php',
- 'CGettextPoFile' => '/i18n/gettext/CGettextPoFile.php',
- 'CChainedLogFilter' => '/logging/CChainedLogFilter.php',
- 'CDbLogRoute' => '/logging/CDbLogRoute.php',
- 'CEmailLogRoute' => '/logging/CEmailLogRoute.php',
- 'CFileLogRoute' => '/logging/CFileLogRoute.php',
- 'CLogFilter' => '/logging/CLogFilter.php',
- 'CLogRoute' => '/logging/CLogRoute.php',
- 'CLogRouter' => '/logging/CLogRouter.php',
- 'CLogger' => '/logging/CLogger.php',
- 'CProfileLogRoute' => '/logging/CProfileLogRoute.php',
- 'CWebLogRoute' => '/logging/CWebLogRoute.php',
- 'CDateTimeParser' => '/utils/CDateTimeParser.php',
- 'CFileHelper' => '/utils/CFileHelper.php',
- 'CFormatter' => '/utils/CFormatter.php',
- 'CMarkdownParser' => '/utils/CMarkdownParser.php',
- 'CPropertyValue' => '/utils/CPropertyValue.php',
- 'CTimestamp' => '/utils/CTimestamp.php',
- 'CVarDumper' => '/utils/CVarDumper.php',
- 'CBooleanValidator' => '/validators/CBooleanValidator.php',
- 'CCaptchaValidator' => '/validators/CCaptchaValidator.php',
- 'CCompareValidator' => '/validators/CCompareValidator.php',
- 'CDateValidator' => '/validators/CDateValidator.php',
- 'CDefaultValueValidator' => '/validators/CDefaultValueValidator.php',
- 'CEmailValidator' => '/validators/CEmailValidator.php',
- 'CExistValidator' => '/validators/CExistValidator.php',
- 'CFileValidator' => '/validators/CFileValidator.php',
- 'CFilterValidator' => '/validators/CFilterValidator.php',
- 'CInlineValidator' => '/validators/CInlineValidator.php',
- 'CNumberValidator' => '/validators/CNumberValidator.php',
- 'CRangeValidator' => '/validators/CRangeValidator.php',
- 'CRegularExpressionValidator' => '/validators/CRegularExpressionValidator.php',
- 'CRequiredValidator' => '/validators/CRequiredValidator.php',
- 'CSafeValidator' => '/validators/CSafeValidator.php',
- 'CStringValidator' => '/validators/CStringValidator.php',
- 'CTypeValidator' => '/validators/CTypeValidator.php',
- 'CUniqueValidator' => '/validators/CUniqueValidator.php',
- 'CUnsafeValidator' => '/validators/CUnsafeValidator.php',
- 'CUrlValidator' => '/validators/CUrlValidator.php',
- 'CValidator' => '/validators/CValidator.php',
- 'CActiveDataProvider' => '/web/CActiveDataProvider.php',
- 'CArrayDataProvider' => '/web/CArrayDataProvider.php',
- 'CAssetManager' => '/web/CAssetManager.php',
- 'CBaseController' => '/web/CBaseController.php',
- 'CCacheHttpSession' => '/web/CCacheHttpSession.php',
- 'CClientScript' => '/web/CClientScript.php',
- 'CController' => '/web/CController.php',
- 'CDataProvider' => '/web/CDataProvider.php',
- 'CDataProviderIterator' => '/web/CDataProviderIterator.php',
- 'CDbHttpSession' => '/web/CDbHttpSession.php',
- 'CExtController' => '/web/CExtController.php',
- 'CFormModel' => '/web/CFormModel.php',
- 'CHttpCookie' => '/web/CHttpCookie.php',
- 'CHttpRequest' => '/web/CHttpRequest.php',
- 'CHttpSession' => '/web/CHttpSession.php',
- 'CHttpSessionIterator' => '/web/CHttpSessionIterator.php',
- 'COutputEvent' => '/web/COutputEvent.php',
- 'CPagination' => '/web/CPagination.php',
- 'CSort' => '/web/CSort.php',
- 'CSqlDataProvider' => '/web/CSqlDataProvider.php',
- 'CTheme' => '/web/CTheme.php',
- 'CThemeManager' => '/web/CThemeManager.php',
- 'CUploadedFile' => '/web/CUploadedFile.php',
- 'CUrlManager' => '/web/CUrlManager.php',
- 'CWebApplication' => '/web/CWebApplication.php',
- 'CWebModule' => '/web/CWebModule.php',
- 'CWidgetFactory' => '/web/CWidgetFactory.php',
- 'CAction' => '/web/actions/CAction.php',
- 'CInlineAction' => '/web/actions/CInlineAction.php',
- 'CViewAction' => '/web/actions/CViewAction.php',
- 'CAccessControlFilter' => '/web/auth/CAccessControlFilter.php',
- 'CAuthAssignment' => '/web/auth/CAuthAssignment.php',
- 'CAuthItem' => '/web/auth/CAuthItem.php',
- 'CAuthManager' => '/web/auth/CAuthManager.php',
- 'CBaseUserIdentity' => '/web/auth/CBaseUserIdentity.php',
- 'CDbAuthManager' => '/web/auth/CDbAuthManager.php',
- 'CPhpAuthManager' => '/web/auth/CPhpAuthManager.php',
- 'CUserIdentity' => '/web/auth/CUserIdentity.php',
- 'CWebUser' => '/web/auth/CWebUser.php',
- 'CFilter' => '/web/filters/CFilter.php',
- 'CFilterChain' => '/web/filters/CFilterChain.php',
- 'CHttpCacheFilter' => '/web/filters/CHttpCacheFilter.php',
- 'CInlineFilter' => '/web/filters/CInlineFilter.php',
- 'CForm' => '/web/form/CForm.php',
- 'CFormButtonElement' => '/web/form/CFormButtonElement.php',
- 'CFormElement' => '/web/form/CFormElement.php',
- 'CFormElementCollection' => '/web/form/CFormElementCollection.php',
- 'CFormInputElement' => '/web/form/CFormInputElement.php',
- 'CFormStringElement' => '/web/form/CFormStringElement.php',
- 'CGoogleApi' => '/web/helpers/CGoogleApi.php',
- 'CHtml' => '/web/helpers/CHtml.php',
- 'CJSON' => '/web/helpers/CJSON.php',
- 'CJavaScript' => '/web/helpers/CJavaScript.php',
- 'CJavaScriptExpression' => '/web/helpers/CJavaScriptExpression.php',
- 'CPradoViewRenderer' => '/web/renderers/CPradoViewRenderer.php',
- 'CViewRenderer' => '/web/renderers/CViewRenderer.php',
- 'CWebService' => '/web/services/CWebService.php',
- 'CWebServiceAction' => '/web/services/CWebServiceAction.php',
- 'CWsdlGenerator' => '/web/services/CWsdlGenerator.php',
- 'CActiveForm' => '/web/widgets/CActiveForm.php',
- 'CAutoComplete' => '/web/widgets/CAutoComplete.php',
- 'CClipWidget' => '/web/widgets/CClipWidget.php',
- 'CContentDecorator' => '/web/widgets/CContentDecorator.php',
- 'CFilterWidget' => '/web/widgets/CFilterWidget.php',
- 'CFlexWidget' => '/web/widgets/CFlexWidget.php',
- 'CHtmlPurifier' => '/web/widgets/CHtmlPurifier.php',
- 'CInputWidget' => '/web/widgets/CInputWidget.php',
- 'CMarkdown' => '/web/widgets/CMarkdown.php',
- 'CMaskedTextField' => '/web/widgets/CMaskedTextField.php',
- 'CMultiFileUpload' => '/web/widgets/CMultiFileUpload.php',
- 'COutputCache' => '/web/widgets/COutputCache.php',
- 'COutputProcessor' => '/web/widgets/COutputProcessor.php',
- 'CStarRating' => '/web/widgets/CStarRating.php',
- 'CTabView' => '/web/widgets/CTabView.php',
- 'CTextHighlighter' => '/web/widgets/CTextHighlighter.php',
- 'CTreeView' => '/web/widgets/CTreeView.php',
- 'CWidget' => '/web/widgets/CWidget.php',
- 'CCaptcha' => '/web/widgets/captcha/CCaptcha.php',
- 'CCaptchaAction' => '/web/widgets/captcha/CCaptchaAction.php',
- 'CBasePager' => '/web/widgets/pagers/CBasePager.php',
- 'CLinkPager' => '/web/widgets/pagers/CLinkPager.php',
- 'CListPager' => '/web/widgets/pagers/CListPager.php',
- );
- }
- spl_autoload_register(array('YiiBase','autoload'));
- class Yii extends YiiBase
- {
- }
- class CComponent
- {
- private $_e;
- private $_m;
- public function __get($name)
- {
- $getter='get'.$name;
- if(method_exists($this,$getter))
- return $this->$getter();
- elseif(strncasecmp($name,'on',2)===0 && method_exists($this,$name))
- {
- // duplicating getEventHandlers() here for performance
- $name=strtolower($name);
- if(!isset($this->_e[$name]))
- $this->_e[$name]=new CList;
- return $this->_e[$name];
- }
- elseif(isset($this->_m[$name]))
- return $this->_m[$name];
- elseif(is_array($this->_m))
- {
- foreach($this->_m as $object)
- {
- if($object->getEnabled() && (property_exists($object,$name) || $object->canGetProperty($name)))
- return $object->$name;
- }
- }
- throw new CException(Yii::t('yii','Property "{class}.{property}" is not defined.',
- array('{class}'=>get_class($this), '{property}'=>$name)));
- }
- public function __set($name,$value)
- {
- $setter='set'.$name;
- if(method_exists($this,$setter))
- return $this->$setter($value);
- elseif(strncasecmp($name,'on',2)===0 && method_exists($this,$name))
- {
- // duplicating getEventHandlers() here for performance
- $name=strtolower($name);
- if(!isset($this->_e[$name]))
- $this->_e[$name]=new CList;
- return $this->_e[$name]->add($value);
- }
- elseif(is_array($this->_m))
- {
- foreach($this->_m as $object)
- {
- if($object->getEnabled() && (property_exists($object,$name) || $object->canSetProperty($name)))
- return $object->$name=$value;
- }
- }
- if(method_exists($this,'get'.$name))
- throw new CException(Yii::t('yii','Property "{class}.{property}" is read only.',
- array('{class}'=>get_class($this), '{property}'=>$name)));
- else
- throw new CException(Yii::t('yii','Property "{class}.{property}" is not defined.',
- array('{class}'=>get_class($this), '{property}'=>$name)));
- }
- public function __isset($name)
- {
- $getter='get'.$name;
- if(method_exists($this,$getter))
- return $this->$getter()!==null;
- elseif(strncasecmp($name,'on',2)===0 && method_exists($this,$name))
- {
- $name=strtolower($name);
- return isset($this->_e[$name]) && $this->_e[$name]->getCount();
- }
- elseif(is_array($this->_m))
- {
- if(isset($this->_m[$name]))
- return true;
- foreach($this->_m as $object)
- {
- if($object->getEnabled() && (property_exists($object,$name) || $object->canGetProperty($name)))
- return $object->$name!==null;
- }
- }
- return false;
- }
- public function __unset($name)
- {
- $setter='set'.$name;
- if(method_exists($this,$setter))
- $this->$setter(null);
- elseif(strncasecmp($name,'on',2)===0 && method_exists($this,$name))
- unset($this->_e[strtolower($name)]);
- elseif(is_array($this->_m))
- {
- if(isset($this->_m[$name]))
- $this->detachBehavior($name);
- else
- {
- foreach($this->_m as $object)
- {
- if($object->getEnabled())
- {
- if(property_exists($object,$name))
- return $object->$name=null;
- elseif($object->canSetProperty($name))
- return $object->$setter(null);
- }
- }
- }
- }
- elseif(method_exists($this,'get'.$name))
- throw new CException(Yii::t('yii','Property "{class}.{property}" is read only.',
- array('{class}'=>get_class($this), '{property}'=>$name)));
- }
- public function __call($name,$parameters)
- {
- if($this->_m!==null)
- {
- foreach($this->_m as $object)
- {
- if($object->getEnabled() && method_exists($object,$name))
- return call_user_func_array(array($object,$name),$parameters);
- }
- }
- if(class_exists('Closure', false) && $this->canGetProperty($name) && $this->$name instanceof Closure)
- return call_user_func_array($this->$name, $parameters);
- throw new CException(Yii::t('yii','{class} and its behaviors do not have a method or closure named "{name}".',
- array('{class}'=>get_class($this), '{name}'=>$name)));
- }
- public function asa($behavior)
- {
- return isset($this->_m[$behavior]) ? $this->_m[$behavior] : null;
- }
- public function attachBehaviors($behaviors)
- {
- foreach($behaviors as $name=>$behavior)
- $this->attachBehavior($name,$behavior);
- }
- public function detachBehaviors()
- {
- if($this->_m!==null)
- {
- foreach($this->_m as $name=>$behavior)
- $this->detachBehavior($name);
- $this->_m=null;
- }
- }
- public function attachBehavior($name,$behavior)
- {
- if(!($behavior instanceof IBehavior))
- $behavior=Yii::createComponent($behavior);
- $behavior->setEnabled(true);
- $behavior->attach($this);
- return $this->_m[$name]=$behavior;
- }
- public function detachBehavior($name)
- {
- if(isset($this->_m[$name]))
- {
- $this->_m[$name]->detach($this);
- $behavior=$this->_m[$name];
- unset($this->_m[$name]);
- return $behavior;
- }
- }
- public function enableBehaviors()
- {
- if($this->_m!==null)
- {
- foreach($this->_m as $behavior)
- $behavior->setEnabled(true);
- }
- }
- public function disableBehaviors()
- {
- if($this->_m!==null)
- {
- foreach($this->_m as $behavior)
- $behavior->setEnabled(false);
- }
- }
- public function enableBehavior($name)
- {
- if(isset($this->_m[$name]))
- $this->_m[$name]->setEnabled(true);
- }
- public function disableBehavior($name)
- {
- if(isset($this->_m[$name]))
- $this->_m[$name]->setEnabled(false);
- }
- public function hasProperty($name)
- {
- return method_exists($this,'get'.$name) || method_exists($this,'set'.$name);
- }
- public function canGetProperty($name)
- {
- return method_exists($this,'get'.$name);
- }
- public function canSetProperty($name)
- {
- return method_exists($this,'set'.$name);
- }
- public function hasEvent($name)
- {
- return !strncasecmp($name,'on',2) && method_exists($this,$name);
- }
- public function hasEventHandler($name)
- {
- $name=strtolower($name);
- return isset($this->_e[$name]) && $this->_e[$name]->getCount()>0;
- }
- public function getEventHandlers($name)
- {
- if($this->hasEvent($name))
- {
- $name=strtolower($name);
- if(!isset($this->_e[$name]))
- $this->_e[$name]=new CList;
- return $this->_e[$name];
- }
- else
- throw new CException(Yii::t('yii','Event "{class}.{event}" is not defined.',
- array('{class}'=>get_class($this), '{event}'=>$name)));
- }
- public function attachEventHandler($name,$handler)
- {
- $this->getEventHandlers($name)->add($handler);
- }
- public function detachEventHandler($name,$handler)
- {
- if($this->hasEventHandler($name))
- return $this->getEventHandlers($name)->remove($handler)!==false;
- else
- return false;
- }
- public function raiseEvent($name,$event)
- {
- $name=strtolower($name);
- if(isset($this->_e[$name]))
- {
- foreach($this->_e[$name] as $handler)
- {
- if(is_string($handler))
- call_user_func($handler,$event);
- elseif(is_callable($handler,true))
- {
- if(is_array($handler))
- {
- // an array: 0 - object, 1 - method name
- list($object,$method)=$handler;
- if(is_string($object)) // static method call
- call_user_func($handler,$event);
- elseif(method_exists($object,$method))
- $object->$method($event);
- else
- throw new CException(Yii::t('yii','Event "{class}.{event}" is attached with an invalid handler "{handler}".',
- array('{class}'=>get_class($this), '{event}'=>$name, '{handler}'=>$handler[1])));
- }
- else // PHP 5.3: anonymous function
- call_user_func($handler,$event);
- }
- else
- throw new CException(Yii::t('yii','Event "{class}.{event}" is attached with an invalid handler "{handler}".',
- array('{class}'=>get_class($this), '{event}'=>$name, '{handler}'=>gettype($handler))));
- // stop further handling if param.handled is set true
- if(($event instanceof CEvent) && $event->handled)
- return;
- }
- }
- elseif(YII_DEBUG && !$this->hasEvent($name))
- throw new CException(Yii::t('yii','Event "{class}.{event}" is not defined.',
- array('{class}'=>get_class($this), '{event}'=>$name)));
- }
- public function evaluateExpression($_expression_,$_data_=array())
- {
- if(is_string($_expression_))
- {
- extract($_data_);
- return eval('return '.$_expression_.';');
- }
- else
- {
- $_data_[]=$this;
- return call_user_func_array($_expression_, $_data_);
- }
- }
- }
- class CEvent extends CComponent
- {
- public $sender;
- public $handled=false;
- public $params;
- public function __construct($sender=null,$params=null)
- {
- $this->sender=$sender;
- $this->params=$params;
- }
- }
- class CEnumerable
- {
- }
- abstract class CModule extends CComponent
- {
- public $preload=array();
- public $behaviors=array();
- private $_id;
- private $_parentModule;
- private $_basePath;
- private $_modulePath;
- private $_params;
- private $_modules=array();
- private $_moduleConfig=array();
- private $_components=array();
- private $_componentConfig=array();
- public function __construct($id,$parent,$config=null)
- {
- $this->_id=$id;
- $this->_parentModule=$parent;
- // set basePath at early as possible to avoid trouble
- if(is_string($config))
- $config=require($config);
- if(isset($config['basePath']))
- {
- $this->setBasePath($config['basePath']);
- unset($config['basePath']);
- }
- Yii::setPathOfAlias($id,$this->getBasePath());
- $this->preinit();
- $this->configure($config);
- $this->attachBehaviors($this->behaviors);
- $this->preloadComponents();
- $this->init();
- }
- public function __get($name)
- {
- if($this->hasComponent($name))
- return $this->getComponent($name);
- else
- return parent::__get($name);
- }
- public function __isset($name)
- {
- if($this->hasComponent($name))
- return $this->getComponent($name)!==null;
- else
- return parent::__isset($name);
- }
- public function getId()
- {
- return $this->_id;
- }
- public function setId($id)
- {
- $this->_id=$id;
- }
- public function getBasePath()
- {
- if($this->_basePath===null)
- {
- $class=new ReflectionClass(get_class($this));
- $this->_basePath=dirname($class->getFileName());
- }
- return $this->_basePath;
- }
- public function setBasePath($path)
- {
- if(($this->_basePath=realpath($path))===false || !is_dir($this->_basePath))
- throw new CException(Yii::t('yii','Base path "{path}" is not a valid directory.',
- array('{path}'=>$path)));
- }
- public function getParams()
- {
- if($this->_params!==null)
- return $this->_params;
- else
- {
- $this->_params=new CAttributeCollection;
- $this->_params->caseSensitive=true;
- return $this->_params;
- }
- }
- public function setParams($value)
- {
- $params=$this->getParams();
- foreach($value as $k=>$v)
- $params->add($k,$v);
- }
- public function getModulePath()
- {
- if($this->_modulePath!==null)
- return $this->_modulePath;
- else
- return $this->_modulePath=$this->getBasePath().DIRECTORY_SEPARATOR.'modules';
- }
- public function setModulePath($value)
- {
- if(($this->_modulePath=realpath($value))===false || !is_dir($this->_modulePath))
- throw new CException(Yii::t('yii','The module path "{path}" is not a valid directory.',
- array('{path}'=>$value)));
- }
- public function setImport($aliases)
- {
- foreach($aliases as $alias)
- Yii::import($alias);
- }
- public function setAliases($mappings)
- {
- foreach($mappings as $name=>$alias)
- {
- if(($path=Yii::getPathOfAlias($alias))!==false)
- Yii::setPathOfAlias($name,$path);
- else
- Yii::setPathOfAlias($name,$alias);
- }
- }
- public function getParentModule()
- {
- return $this->_parentModule;
- }
- public function getModule($id)
- {
- if(isset($this->_modules[$id]) || array_key_exists($id,$this->_modules))
- return $this->_modules[$id];
- elseif(isset($this->_moduleConfig[$id]))
- {
- $config=$this->_moduleConfig[$id];
- if(!isset($config['enabled']) || $config['enabled'])
- {
- $class=$config['class'];
- unset($config['class'], $config['enabled']);
- if($this===Yii::app())
- $module=Yii::createComponent($class,$id,null,$config);
- else
- $module=Yii::createComponent($class,$this->getId().'/'.$id,$this,$config);
- return $this->_modules[$id]=$module;
- }
- }
- }
- public function hasModule($id)
- {
- return isset($this->_moduleConfig[$id]) || isset($this->_modules[$id]);
- }
- public function getModules()
- {
- return $this->_moduleConfig;
- }
- public function setModules($modules)
- {
- foreach($modules as $id=>$module)
- {
- if(is_int($id))
- {
- $id=$module;
- $module=array();
- }
- if(!isset($module['class']))
- {
- Yii::setPathOfAlias($id,$this->getModulePath().DIRECTORY_SEPARATOR.$id);
- $module['class']=$id.'.'.ucfirst($id).'Module';
- }
- if(isset($this->_moduleConfig[$id]))
- $this->_moduleConfig[$id]=CMap::mergeArray($this->_moduleConfig[$id],$module);
- else
- $this->_moduleConfig[$id]=$module;
- }
- }
- public function hasComponent($id)
- {
- return isset($this->_components[$id]) || isset($this->_componentConfig[$id]);
- }
- public function getComponent($id,$createIfNull=true)
- {
- if(isset($this->_components[$id]))
- return $this->_components[$id];
- elseif(isset($this->_componentConfig[$id]) && $createIfNull)
- {
- $config=$this->_componentConfig[$id];
- if(!isset($config['enabled']) || $config['enabled'])
- {
- unset($config['enabled']);
- $component=Yii::createComponent($config);
- $component->init();
- return $this->_components[$id]=$component;
- }
- }
- }
- public function setComponent($id,$component,$merge=true)
- {
- if($component===null)
- {
- unset($this->_components[$id]);
- return;
- }
- elseif($component instanceof IApplicationComponent)
- {
- $this->_components[$id]=$component;
- if(!$component->getIsInitialized())
- $component->init();
- return;
- }
- elseif(isset($this->_components[$id]))
- {
- if(isset($component['class']) && get_class($this->_components[$id])!==$component['class'])
- {
- unset($this->_components[$id]);
- $this->_componentConfig[$id]=$component; //we should ignore merge here
- return;
- }
- foreach($component as $key=>$value)
- {
- if($key!=='class')
- $this->_components[$id]->$key=$value;
- }
- }
- elseif(isset($this->_componentConfig[$id]['class'],$component['class'])
- && $this->_componentConfig[$id]['class']!==$component['class'])
- {
- $this->_componentConfig[$id]=$component; //we should ignore merge here
- return;
- }
- if(isset($this->_componentConfig[$id]) && $merge)
- $this->_componentConfig[$id]=CMap::mergeArray($this->_componentConfig[$id],$component);
- else
- $this->_componentConfig[$id]=$component;
- }
- public function getComponents($loadedOnly=true)
- {
- if($loadedOnly)
- return $this->_components;
- else
- return array_merge($this->_componentConfig, $this->_components);
- }
- public function setComponents($components,$merge=true)
- {
- foreach($components as $id=>$component)
- $this->setComponent($id,$component,$merge);
- }
- public function configure($config)
- {
- if(is_array($config))
- {
- foreach($config as $key=>$value)
- $this->$key=$value;
- }
- }
- protected function preloadComponents()
- {
- foreach($this->preload as $id)
- $this->getComponent($id);
- }
- protected function preinit()
- {
- }
- protected function init()
- {
- }
- }
- abstract class CApplication extends CModule
- {
- public $name='My Application';
- public $charset='UTF-8';
- public $sourceLanguage='en_us';
- private $_id;
- private $_basePath;
- private $_runtimePath;
- private $_extensionPath;
- private $_globalState;
- private $_stateChanged;
- private $_ended=false;
- private $_language;
- private $_homeUrl;
- abstract public function processRequest();
- public function __construct($config=null)
- {
- Yii::setApplication($this);
- // set basePath at early as possible to avoid trouble
- if(is_string($config))
- $config=require($config);
- if(isset($config['basePath']))
- {
- $this->setBasePath($config['basePath']);
- unset($config['basePath']);
- }
- else
- $this->setBasePath('protected');
- Yii::setPathOfAlias('application',$this->getBasePath());
- Yii::setPathOfAlias('webroot',dirname($_SERVER['SCRIPT_FILENAME']));
- Yii::setPathOfAlias('ext',$this->getBasePath().DIRECTORY_SEPARATOR.'extensions');
- $this->preinit();
- $this->initSystemHandlers();
- $this->registerCoreComponents();
- $this->configure($config);
- $this->attachBehaviors($this->behaviors);
- $this->preloadComponents();
- $this->init();
- }
- public function run()
- {
- if($this->hasEventHandler('onBeginRequest'))
- $this->onBeginRequest(new CEvent($this));
- register_shutdown_function(array($this,'end'),0,false);
- $this->processRequest();
- if($this->hasEventHandler('onEndRequest'))
- $this->onEndRequest(new CEvent($this));
- }
- public function end($status=0,$exit=true)
- {
- if($this->hasEventHandler('onEndRequest'))
- $this->onEndRequest(new CEvent($this));
- if($exit)
- exit($status);
- }
- public function onBeginRequest($event)
- {
- $this->raiseEvent('onBeginRequest',$event);
- }
- public function onEndRequest($event)
- {
- if(!$this->_ended)
- {
- $this->_ended=true;
- $this->raiseEvent('onEndRequest',$event);
- }
- }
- public function getId()
- {
- if($this->_id!==null)
- return $this->_id;
- else
- return $this->_id=sprintf('%x',crc32($this->getBasePath().$this->name));
- }
- public function setId($id)
- {
- $this->_id=$id;
- }
- public function getBasePath()
- {
- return $this->_basePath;
- }
- public function setBasePath($path)
- {
- if(($this->_basePath=realpath($path))===false || !is_dir($this->_basePath))
- throw new CException(Yii::t('yii','Application base path "{path}" is not a valid directory.',
- array('{path}'=>$path)));
- }
- public function getRuntimePath()
- {
- if($this->_runtimePath!==null)
- return $this->_runtimePath;
- else
- {
- $this->setRuntimePath($this->getBasePath().DIRECTORY_SEPARATOR.'runtime');
- return $this->_runtimePath;
- }
- }
- public function setRuntimePath($path)
- {
- if(($runtimePath=realpath($path))===false || !is_dir($runtimePath) || !is_writable($runtimePath))
- throw new CException(Yii::t('yii','Application runtime path "{path}" is not valid. Please make sure it is a directory writable by the Web server process.',
- array('{path}'=>$path)));
- $this->_runtimePath=$runtimePath;
- }
- public function getExtensionPath()
- {
- return Yii::getPathOfAlias('ext');
- }
- public function setExtensionPath($path)
- {
- if(($extensionPath=realpath($path))===false || !is_dir($extensionPath))
- throw new CException(Yii::t('yii','Extension path "{path}" does not exist.',
- array('{path}'=>$path)));
- Yii::setPathOfAlias('ext',$extensionPath);
- }
- public function getLanguage()
- {
- return $this->_language===null ? $this->sourceLanguage : $this->_language;
- }
- public function setLanguage($language)
- {
- $this->_language=$language;
- }
- public function getTimeZone()
- {
- return date_default_timezone_get();
- }
- public function setTimeZone($value)
- {
- date_default_timezone_set($value);
- }
- public function findLocalizedFile($srcFile,$srcLanguage=null,$language=null)
- {
- if($srcLanguage===null)
- $srcLanguage=$this->sourceLanguage;
- if($language===null)
- $language=$this->getLanguage();
- if($language===$srcLanguage)
- return $srcFile;
- $desiredFile=dirname($srcFile).DIRECTORY_SEPARATOR.$language.DIRECTORY_SEPARATOR.basename($srcFile);
- return is_file($desiredFile) ? $desiredFile : $srcFile;
- }
- public function getLocale($localeID=null)
- {
- return CLocale::getInstance($localeID===null?$this->getLanguage():$localeID);
- }
- public function getLocaleDataPath()
- {
- return CLocale::$dataPath===null ? Yii::getPathOfAlias('system.i18n.data') : CLocale::$dataPath;
- }
- public function setLocaleDataPath($value)
- {
- CLocale::$dataPath=$value;
- }
- public function getNumberFormatter()
- {
- return $this->getLocale()->getNumberFormatter();
- }
- public function getDateFormatter()
- {
- return $this->getLocale()->getDateFormatter();
- }
- public function getDb()
- {
- return $this->getComponent('db');
- }
- public function getErrorHandler()
- {
- return $this->getComponent('errorHandler');
- }
- public function getSecurityManager()
- {
- return $this->getComponent('securityManager');
- }
- public function getStatePersister()
- {
- return $this->getComponent('statePersister');
- }
- public function getCache()
- {
- return $this->getComponent('cache');
- }
- public function getCoreMessages()
- {
- return $this->getComponent('coreMessages');
- }
- public function getMessages()
- {
- return $this->getComponent('messages');
- }
- public function getRequest()
- {
- return $this->getComponent('request');
- }
- public function getUrlManager()
- {
- return $this->getComponent('urlManager');
- }
- public function getController()
- {
- return null;
- }
- public function createUrl($route,$params=array(),$ampersand='&')
- {
- return $this->getUrlManager()->createUrl($route,$params,$ampersand);
- }
- public function createAbsoluteUrl($route,$params=array(),$schema='',$ampersand='&')
- {
- $url=$this->createUrl($route,$params,$ampersand);
- if(strpos($url,'http')===0)
- return $url;
- else
- return $this->getRequest()->getHostInfo($schema).$url;
- }
- public function getBaseUrl($absolute=false)
- {
- return $this->getRequest()->getBaseUrl($absolute);
- }
- public function getHomeUrl()
- {
- if($this->_homeUrl===null)
- {
- if($this->getUrlManager()->showScriptName)
- return $this->getRequest()->getScriptUrl();
- else
- return $this->getRequest()->getBaseUrl().'/';
- }
- else
- return $this->_homeUrl;
- }
- public function setHomeUrl($value)
- {
- $this->_homeUrl=$value;
- }
- public function getGlobalState($key,$defaultValue=null)
- {
- if($this->_globalState===null)
- $this->loadGlobalState();
- if(isset($this->_globalState[$key]))
- return $this->_globalState[$key];
- else
- return $defaultValue;
- }
- public function setGlobalState($key,$value,$defaultValue=null)
- {
- if($this->_globalState===null)
- $this->loadGlobalState();
- $changed=$this->_stateChanged;
- if($value===$defaultValue)
- {
- if(isset($this->_globalState[$key]))
- {
- unset($this->_globalState[$key]);
- $this->_stateChanged=true;
- }
- }
- elseif(!isset($this->_globalState[$key]) || $this->_globalState[$key]!==$value)
- {
- $this->_globalState[$key]=$value;
- $this->_stateChanged=true;
- }
- if($this->_stateChanged!==$changed)
- $this->attachEventHandler('onEndRequest',array($this,'saveGlobalState'));
- }
- public function clearGlobalState($key)
- {
- $this->setGlobalState($key,true,true);
- }
- public function loadGlobalState()
- {
- $persister=$this->getStatePersister();
- if(($this->_globalState=$persister->load())===null)
- $this->_globalState=array();
- $this->_stateChanged=false;
- $this->detachEventHandler('onEndRequest',array($this,'saveGlobalState'));
- }
- public function saveGlobalState()
- {
- if($this->_stateChanged)
- {
- $this->_stateChanged=false;
- $this->detachEventHandler('onEndRequest',array($this,'saveGlobalState'));
- $this->getStatePersister()->save($this->_globalState);
- }
- }
- public function handleException($exception)
- {
- // disable error capturing to avoid recursive errors
- restore_error_handler();
- restore_exception_handler();
- $category='exception.'.get_class($exception);
- if($exception instanceof CHttpException)
- $category.='.'.$exception->statusCode;
- // php <5.2 doesn't support string conversion auto-magically
- $message=$exception->__toString();
- if(isset($_SERVER['REQUEST_URI']))
- $message.="\nREQUEST_URI=".$_SERVER['REQUEST_URI'];
- if(isset($_SERVER['HTTP_REFERER']))
- $message.="\nHTTP_REFERER=".$_SERVER['HTTP_REFERER'];
- $message.="\n---";
- Yii::log($message,CLogger::LEVEL_ERROR,$category);
- try
- {
- $event=new CExceptionEvent($this,$exception);
- $this->onException($event);
- if(!$event->handled)
- {
- // try an error handler
- if(($handler=$this->getErrorHandler())!==null)
- $handler->handle($event);
- else
- $this->displayException($exception);
- }
- }
- catch(Exception $e)
- {
- $this->displayException($e);
- }
- try
- {
- $this->end(1);
- }
- catch(Exception $e)
- {
- // use the most primitive way to log error
- $msg = get_class($e).': '.$e->getMessage().' ('.$e->getFile().':'.$e->getLine().")\n";
- $msg .= $e->getTraceAsString()."\n";
- $msg .= "Previous exception:\n";
- $msg .= get_class($exception).': '.$exception->getMessage().' ('.$exception->getFile().':'.$exception->getLine().")\n";
- $msg .= $exception->getTraceAsString()."\n";
- $msg .= '$_SERVER='.var_export($_SERVER,true);
- error_log($msg);
- exit(1);
- }
- }
- public function handleError($code,$message,$file,$line)
- {
- if($code & error_reporting())
- {
- // disable error capturing to avoid recursive errors
- restore_error_handler();
- restore_exception_handler();
- $log="$message ($file:$line)\nStack trace:\n";
- $trace=debug_backtrace();
- // skip the first 3 stacks as they do not tell the error position
- if(count($trace)>3)
- $trace=array_slice($trace,3);
- foreach($trace as $i=>$t)
- {
- if(!isset($t['file']))
- $t['file']='unknown';
- if(!isset($t['line']))
- $t['line']=0;
- if(!isset($t['function']))
- $t['function']='unknown';
- $log.="#$i {$t['file']}({$t['line']}): ";
- if(isset($t['object']) && is_object($t['object']))
- $log.=get_class($t['object']).'->';
- $log.="{$t['function']}()\n";
- }
- if(isset($_SERVER['REQUEST_URI']))
- $log.='REQUEST_URI='.$_SERVER['REQUEST_URI'];
- Yii::log($log,CLogger::LEVEL_ERROR,'php');
- try
- {
- Yii::import('CErrorEvent',true);
- $event=new CErrorEvent($this,$code,$message,$file,$line);
- $this->onError($event);
- if(!$event->handled)
- {
- // try an error handler
- if(($handler=$this->getErrorHandler())!==null)
- $handler->handle($event);
- else
- $this->displayError($code,$message,$file,$line);
- }
- }
- catch(Exception $e)
- {
- $this->displayException($e);
- }
- try
- {
- $this->end(1);
- }
- catch(Exception $e)
- {
- // use the most primitive way to log error
- $msg = get_class($e).': '.$e->getMessage().' ('.$e->getFile().':'.$e->getLine().")\n";
- $msg .= $e->getTraceAsString()."\n";
- $msg .= "Previous error:\n";
- $msg .= $log."\n";
- $msg .= '$_SERVER='.var_export($_SERVER,true);
- error_log($msg);
- exit(1);
- }
- }
- }
- public function onException($event)
- {
- $this->raiseEvent('onException',$event);
- }
- public function onError($event)
- {
- $this->raiseEvent('onError',$event);
- }
- public function displayError($code,$message,$file,$line)
- {
- if(YII_DEBUG)
- {
- echo "<h1>PHP Error [$code]</h1>\n";
- echo "<p>$message ($file:$line)</p>\n";
- echo '<pre>';
- $trace=debug_backtrace();
- // skip the first 3 stacks as they do not tell the error position
- if(count($trace)>3)
- $trace=array_slice($trace,3);
- foreach($trace as $i=>$t)
- {
- if(!isset($t['file']))
- $t['file']='unknown';
- if(!isset($t['line']))
- $t['line']=0;
- if(!isset($t['function']))
- $t['function']='unknown';
- echo "#$i {$t['file']}({$t['line']}): ";
- if(isset($t['object']) && is_object($t['object']))
- echo get_class($t['object']).'->';
- echo "{$t['function']}()\n";
- }
- echo '</pre>';
- }
- else
- {
- echo "<h1>PHP Error [$code]</h1>\n";
- echo "<p>$message</p>\n";
- }
- }
- public function displayException($exception)
- {
- if(YII_DEBUG)
- {
- echo '<h1>'.get_class($exception)."</h1>\n";
- echo '<p>'.$exception->getMessage().' ('.$exception->getFile().':'.$exception->getLine().')</p>';
- echo '<pre>'.$exception->getTraceAsString().'</pre>';
- }
- else
- {
- echo '<h1>'.get_class($exception)."</h1>\n";
- echo '<p>'.$exception->getMessage().'</p>';
- }
- }
- protected function initSystemHandlers()
- {
- if(YII_ENABLE_EXCEPTION_HANDLER)
- set_exception_handler(array($this,'handleException'));
- if(YII_ENABLE_ERROR_HANDLER)
- set_error_handler(array($this,'handleError'),error_reporting());
- }
- protected function registerCoreComponents()…
Large files files are truncated, but you can click here to view the full file