PageRenderTime 99ms CodeModel.GetById 19ms app.highlight 56ms RepoModel.GetById 1ms app.codeStats 2ms

/framework/yiilite.php

https://bitbucket.org/21h/torchok-anon
PHP | 9013 lines | 8958 code | 2 blank | 53 comment | 753 complexity | 686ebec729c2bae2bd6433419f56228f MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1<?php
   2/**
   3 * Yii bootstrap file.
   4 *
   5 * This file is automatically generated using 'build lite' command.
   6 * It is the result of merging commonly used Yii class files with
   7 * comments and trace statements removed away.
   8 *
   9 * By using this file instead of yii.php, an Yii application may
  10 * improve performance due to the reduction of PHP parsing time.
  11 * The performance improvement is especially obvious when PHP APC extension
  12 * is enabled.
  13 *
  14 * DO NOT modify this file manually.
  15 *
  16 * @author Qiang Xue <qiang.xue@gmail.com>
  17 * @link http://www.yiiframework.com/
  18 * @copyright Copyright &copy; 2008-2011 Yii Software LLC
  19 * @license http://www.yiiframework.com/license/
  20 * @version $Id: yiilite.php 2799 2011-01-01 19:31:13Z qiang.xue $
  21 * @since 1.0
  22 */
  23
  24
  25defined('YII_BEGIN_TIME') or define('YII_BEGIN_TIME',microtime(true));
  26defined('YII_DEBUG') or define('YII_DEBUG',false);
  27defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',0);
  28defined('YII_ENABLE_EXCEPTION_HANDLER') or define('YII_ENABLE_EXCEPTION_HANDLER',true);
  29defined('YII_ENABLE_ERROR_HANDLER') or define('YII_ENABLE_ERROR_HANDLER',true);
  30defined('YII_PATH') or define('YII_PATH',dirname(__FILE__));
  31defined('YII_ZII_PATH') or define('YII_ZII_PATH',YII_PATH.DIRECTORY_SEPARATOR.'zii');
  32class YiiBase
  33{
  34	public static $classMap=array();
  35	private static $_aliases=array('system'=>YII_PATH,'zii'=>YII_ZII_PATH); // alias => path
  36	private static $_imports=array();					// alias => class name or directory
  37	private static $_includePaths;						// list of include paths
  38	private static $_app;
  39	private static $_logger;
  40	public static function getVersion()
  41	{
  42		return '1.1.6-dev';
  43	}
  44	public static function createWebApplication($config=null)
  45	{
  46		return self::createApplication('CWebApplication',$config);
  47	}
  48	public static function createConsoleApplication($config=null)
  49	{
  50		return self::createApplication('CConsoleApplication',$config);
  51	}
  52	public static function createApplication($class,$config=null)
  53	{
  54		return new $class($config);
  55	}
  56	public static function app()
  57	{
  58		return self::$_app;
  59	}
  60	public static function setApplication($app)
  61	{
  62		if(self::$_app===null || $app===null)
  63			self::$_app=$app;
  64		else
  65			throw new CException(Yii::t('yii','Yii application can only be created once.'));
  66	}
  67	public static function getFrameworkPath()
  68	{
  69		return YII_PATH;
  70	}
  71	public static function createComponent($config)
  72	{
  73		if(is_string($config))
  74		{
  75			$type=$config;
  76			$config=array();
  77		}
  78		else if(isset($config['class']))
  79		{
  80			$type=$config['class'];
  81			unset($config['class']);
  82		}
  83		else
  84			throw new CException(Yii::t('yii','Object configuration must be an array containing a "class" element.'));
  85		if(!class_exists($type,false))
  86			$type=Yii::import($type,true);
  87		if(($n=func_num_args())>1)
  88		{
  89			$args=func_get_args();
  90			if($n===2)
  91				$object=new $type($args[1]);
  92			else if($n===3)
  93				$object=new $type($args[1],$args[2]);
  94			else if($n===4)
  95				$object=new $type($args[1],$args[2],$args[3]);
  96			else
  97			{
  98				unset($args[0]);
  99				$class=new ReflectionClass($type);
 100				// Note: ReflectionClass::newInstanceArgs() is available for PHP 5.1.3+
 101				// $object=$class->newInstanceArgs($args);
 102				$object=call_user_func_array(array($class,'newInstance'),$args);
 103			}
 104		}
 105		else
 106			$object=new $type;
 107		foreach($config as $key=>$value)
 108			$object->$key=$value;
 109		return $object;
 110	}
 111	public static function import($alias,$forceInclude=false)
 112	{
 113		if(isset(self::$_imports[$alias]))  // previously imported
 114			return self::$_imports[$alias];
 115		if(class_exists($alias,false) || interface_exists($alias,false))
 116			return self::$_imports[$alias]=$alias;
 117		if(($pos=strrpos($alias,'\\'))!==false) // a class name in PHP 5.3 namespace format
 118		{
 119			$namespace=str_replace('\\','.',ltrim(substr($alias,0,$pos),'\\'));
 120			if(($path=self::getPathOfAlias($namespace))!==false)
 121			{
 122				$classFile=$path.DIRECTORY_SEPARATOR.substr($alias,$pos+1).'.php';
 123				if($forceInclude)
 124				{
 125					if(is_file($classFile))
 126						require($classFile);
 127					else
 128						throw new CException(Yii::t('yii','Alias "{alias}" is invalid. Make sure it points to an existing PHP file.',array('{alias}'=>$alias)));
 129					self::$_imports[$alias]=$alias;
 130				}
 131				else
 132					self::$classMap[$alias]=$classFile;
 133				return $alias;
 134			}
 135			else
 136				throw new CException(Yii::t('yii','Alias "{alias}" is invalid. Make sure it points to an existing directory.',
 137					array('{alias}'=>$namespace)));
 138		}
 139		if(($pos=strrpos($alias,'.'))===false)  // a simple class name
 140		{
 141			if($forceInclude && self::autoload($alias))
 142				self::$_imports[$alias]=$alias;
 143			return $alias;
 144		}
 145		$className=(string)substr($alias,$pos+1);
 146		$isClass=$className!=='*';
 147		if($isClass && (class_exists($className,false) || interface_exists($className,false)))
 148			return self::$_imports[$alias]=$className;
 149		if(($path=self::getPathOfAlias($alias))!==false)
 150		{
 151			if($isClass)
 152			{
 153				if($forceInclude)
 154				{
 155					if(is_file($path.'.php'))
 156						require($path.'.php');
 157					else
 158						throw new CException(Yii::t('yii','Alias "{alias}" is invalid. Make sure it points to an existing PHP file.',array('{alias}'=>$alias)));
 159					self::$_imports[$alias]=$className;
 160				}
 161				else
 162					self::$classMap[$className]=$path.'.php';
 163				return $className;
 164			}
 165			else  // a directory
 166			{
 167				if(self::$_includePaths===null)
 168				{
 169					self::$_includePaths=array_unique(explode(PATH_SEPARATOR,get_include_path()));
 170					if(($pos=array_search('.',self::$_includePaths,true))!==false)
 171						unset(self::$_includePaths[$pos]);
 172				}
 173				array_unshift(self::$_includePaths,$path);
 174				if(set_include_path('.'.PATH_SEPARATOR.implode(PATH_SEPARATOR,self::$_includePaths))===false)
 175					throw new CException(Yii::t('yii','Unable to import "{alias}". Please check your server configuration to make sure you are allowed to change PHP include_path.',array('{alias}'=>$alias)));
 176				return self::$_imports[$alias]=$path;
 177			}
 178		}
 179		else
 180			throw new CException(Yii::t('yii','Alias "{alias}" is invalid. Make sure it points to an existing directory or file.',
 181				array('{alias}'=>$alias)));
 182	}
 183	public static function getPathOfAlias($alias)
 184	{
 185		if(isset(self::$_aliases[$alias]))
 186			return self::$_aliases[$alias];
 187		else if(($pos=strpos($alias,'.'))!==false)
 188		{
 189			$rootAlias=substr($alias,0,$pos);
 190			if(isset(self::$_aliases[$rootAlias]))
 191				return self::$_aliases[$alias]=rtrim(self::$_aliases[$rootAlias].DIRECTORY_SEPARATOR.str_replace('.',DIRECTORY_SEPARATOR,substr($alias,$pos+1)),'*'.DIRECTORY_SEPARATOR);
 192			else if(self::$_app instanceof CWebApplication)
 193			{
 194				if(self::$_app->findModule($rootAlias)!==null)
 195					return self::getPathOfAlias($alias);
 196			}
 197		}
 198		return false;
 199	}
 200	public static function setPathOfAlias($alias,$path)
 201	{
 202		if(empty($path))
 203			unset(self::$_aliases[$alias]);
 204		else
 205			self::$_aliases[$alias]=rtrim($path,'\\/');
 206	}
 207	public static function autoload($className)
 208	{
 209		// use include so that the error PHP file may appear
 210		if(isset(self::$_coreClasses[$className]))
 211			include(YII_PATH.self::$_coreClasses[$className]);
 212		else if(isset(self::$classMap[$className]))
 213			include(self::$classMap[$className]);
 214		else
 215		{
 216			if(strpos($className,'\\')===false)
 217				include($className.'.php');
 218			else  // class name with namespace in PHP 5.3
 219			{
 220				$namespace=str_replace('\\','.',ltrim($className,'\\'));
 221				if(($path=self::getPathOfAlias($namespace))!==false)
 222					include($path.'.php');
 223				else
 224					return false;
 225			}
 226			return class_exists($className,false) || interface_exists($className,false);
 227		}
 228		return true;
 229	}
 230	public static function trace($msg,$category='application')
 231	{
 232		if(YII_DEBUG)
 233			self::log($msg,CLogger::LEVEL_TRACE,$category);
 234	}
 235	public static function log($msg,$level=CLogger::LEVEL_INFO,$category='application')
 236	{
 237		if(self::$_logger===null)
 238			self::$_logger=new CLogger;
 239		if(YII_DEBUG && YII_TRACE_LEVEL>0 && $level!==CLogger::LEVEL_PROFILE)
 240		{
 241			$traces=debug_backtrace();
 242			$count=0;
 243			foreach($traces as $trace)
 244			{
 245				if(isset($trace['file'],$trace['line']))
 246				{
 247					$className=substr(basename($trace['file']),0,-4);
 248					if(!isset(self::$_coreClasses[$className]) && $className!=='YiiBase')
 249					{
 250						$msg.="\nin ".$trace['file'].' ('.$trace['line'].')';
 251						if(++$count>=YII_TRACE_LEVEL)
 252							break;
 253					}
 254				}
 255			}
 256		}
 257		self::$_logger->log($msg,$level,$category);
 258	}
 259	public static function beginProfile($token,$category='application')
 260	{
 261		self::log('begin:'.$token,CLogger::LEVEL_PROFILE,$category);
 262	}
 263	public static function endProfile($token,$category='application')
 264	{
 265		self::log('end:'.$token,CLogger::LEVEL_PROFILE,$category);
 266	}
 267	public static function getLogger()
 268	{
 269		if(self::$_logger!==null)
 270			return self::$_logger;
 271		else
 272			return self::$_logger=new CLogger;
 273	}
 274	public static function powered()
 275	{
 276		return 'Powered by <a href="http://www.yiiframework.com/" rel="external">Yii Framework</a>.';
 277	}
 278	public static function t($category,$message,$params=array(),$source=null,$language=null)
 279	{
 280		if(self::$_app!==null)
 281		{
 282			if($source===null)
 283				$source=($category==='yii'||$category==='zii')?'coreMessages':'messages';
 284			if(($source=self::$_app->getComponent($source))!==null)
 285				$message=$source->translate($category,$message,$language);
 286		}
 287		if($params===array())
 288			return $message;
 289		if(isset($params[0])) // number choice
 290		{
 291			$message=CChoiceFormat::format($message,$params[0]);
 292			unset($params[0]);
 293		}
 294		return $params!==array() ? strtr($message,$params) : $message;
 295	}
 296	public static function registerAutoloader($callback)
 297	{
 298		spl_autoload_unregister(array('YiiBase','autoload'));
 299		spl_autoload_register($callback);
 300		spl_autoload_register(array('YiiBase','autoload'));
 301	}
 302	private static $_coreClasses=array(
 303		'CApplication' => '/base/CApplication.php',
 304		'CApplicationComponent' => '/base/CApplicationComponent.php',
 305		'CBehavior' => '/base/CBehavior.php',
 306		'CComponent' => '/base/CComponent.php',
 307		'CErrorEvent' => '/base/CErrorEvent.php',
 308		'CErrorHandler' => '/base/CErrorHandler.php',
 309		'CException' => '/base/CException.php',
 310		'CExceptionEvent' => '/base/CExceptionEvent.php',
 311		'CHttpException' => '/base/CHttpException.php',
 312		'CModel' => '/base/CModel.php',
 313		'CModelBehavior' => '/base/CModelBehavior.php',
 314		'CModelEvent' => '/base/CModelEvent.php',
 315		'CModule' => '/base/CModule.php',
 316		'CSecurityManager' => '/base/CSecurityManager.php',
 317		'CStatePersister' => '/base/CStatePersister.php',
 318		'CApcCache' => '/caching/CApcCache.php',
 319		'CCache' => '/caching/CCache.php',
 320		'CDbCache' => '/caching/CDbCache.php',
 321		'CDummyCache' => '/caching/CDummyCache.php',
 322		'CEAcceleratorCache' => '/caching/CEAcceleratorCache.php',
 323		'CFileCache' => '/caching/CFileCache.php',
 324		'CMemCache' => '/caching/CMemCache.php',
 325		'CWinCache' => '/caching/CWinCache.php',
 326		'CXCache' => '/caching/CXCache.php',
 327		'CZendDataCache' => '/caching/CZendDataCache.php',
 328		'CCacheDependency' => '/caching/dependencies/CCacheDependency.php',
 329		'CChainedCacheDependency' => '/caching/dependencies/CChainedCacheDependency.php',
 330		'CDbCacheDependency' => '/caching/dependencies/CDbCacheDependency.php',
 331		'CDirectoryCacheDependency' => '/caching/dependencies/CDirectoryCacheDependency.php',
 332		'CExpressionDependency' => '/caching/dependencies/CExpressionDependency.php',
 333		'CFileCacheDependency' => '/caching/dependencies/CFileCacheDependency.php',
 334		'CGlobalStateCacheDependency' => '/caching/dependencies/CGlobalStateCacheDependency.php',
 335		'CAttributeCollection' => '/collections/CAttributeCollection.php',
 336		'CConfiguration' => '/collections/CConfiguration.php',
 337		'CList' => '/collections/CList.php',
 338		'CListIterator' => '/collections/CListIterator.php',
 339		'CMap' => '/collections/CMap.php',
 340		'CMapIterator' => '/collections/CMapIterator.php',
 341		'CQueue' => '/collections/CQueue.php',
 342		'CQueueIterator' => '/collections/CQueueIterator.php',
 343		'CStack' => '/collections/CStack.php',
 344		'CStackIterator' => '/collections/CStackIterator.php',
 345		'CTypedList' => '/collections/CTypedList.php',
 346		'CTypedMap' => '/collections/CTypedMap.php',
 347		'CConsoleApplication' => '/console/CConsoleApplication.php',
 348		'CConsoleCommand' => '/console/CConsoleCommand.php',
 349		'CConsoleCommandRunner' => '/console/CConsoleCommandRunner.php',
 350		'CHelpCommand' => '/console/CHelpCommand.php',
 351		'CDbCommand' => '/db/CDbCommand.php',
 352		'CDbConnection' => '/db/CDbConnection.php',
 353		'CDbDataReader' => '/db/CDbDataReader.php',
 354		'CDbException' => '/db/CDbException.php',
 355		'CDbMigration' => '/db/CDbMigration.php',
 356		'CDbTransaction' => '/db/CDbTransaction.php',
 357		'CActiveFinder' => '/db/ar/CActiveFinder.php',
 358		'CActiveRecord' => '/db/ar/CActiveRecord.php',
 359		'CActiveRecordBehavior' => '/db/ar/CActiveRecordBehavior.php',
 360		'CDbColumnSchema' => '/db/schema/CDbColumnSchema.php',
 361		'CDbCommandBuilder' => '/db/schema/CDbCommandBuilder.php',
 362		'CDbCriteria' => '/db/schema/CDbCriteria.php',
 363		'CDbExpression' => '/db/schema/CDbExpression.php',
 364		'CDbSchema' => '/db/schema/CDbSchema.php',
 365		'CDbTableSchema' => '/db/schema/CDbTableSchema.php',
 366		'CMssqlColumnSchema' => '/db/schema/mssql/CMssqlColumnSchema.php',
 367		'CMssqlCommandBuilder' => '/db/schema/mssql/CMssqlCommandBuilder.php',
 368		'CMssqlPdoAdapter' => '/db/schema/mssql/CMssqlPdoAdapter.php',
 369		'CMssqlSchema' => '/db/schema/mssql/CMssqlSchema.php',
 370		'CMssqlTableSchema' => '/db/schema/mssql/CMssqlTableSchema.php',
 371		'CMysqlColumnSchema' => '/db/schema/mysql/CMysqlColumnSchema.php',
 372		'CMysqlSchema' => '/db/schema/mysql/CMysqlSchema.php',
 373		'CMysqlTableSchema' => '/db/schema/mysql/CMysqlTableSchema.php',
 374		'COciColumnSchema' => '/db/schema/oci/COciColumnSchema.php',
 375		'COciCommandBuilder' => '/db/schema/oci/COciCommandBuilder.php',
 376		'COciSchema' => '/db/schema/oci/COciSchema.php',
 377		'COciTableSchema' => '/db/schema/oci/COciTableSchema.php',
 378		'CPgsqlColumnSchema' => '/db/schema/pgsql/CPgsqlColumnSchema.php',
 379		'CPgsqlSchema' => '/db/schema/pgsql/CPgsqlSchema.php',
 380		'CPgsqlTableSchema' => '/db/schema/pgsql/CPgsqlTableSchema.php',
 381		'CSqliteColumnSchema' => '/db/schema/sqlite/CSqliteColumnSchema.php',
 382		'CSqliteCommandBuilder' => '/db/schema/sqlite/CSqliteCommandBuilder.php',
 383		'CSqliteSchema' => '/db/schema/sqlite/CSqliteSchema.php',
 384		'CChoiceFormat' => '/i18n/CChoiceFormat.php',
 385		'CDateFormatter' => '/i18n/CDateFormatter.php',
 386		'CDbMessageSource' => '/i18n/CDbMessageSource.php',
 387		'CGettextMessageSource' => '/i18n/CGettextMessageSource.php',
 388		'CLocale' => '/i18n/CLocale.php',
 389		'CMessageSource' => '/i18n/CMessageSource.php',
 390		'CNumberFormatter' => '/i18n/CNumberFormatter.php',
 391		'CPhpMessageSource' => '/i18n/CPhpMessageSource.php',
 392		'CGettextFile' => '/i18n/gettext/CGettextFile.php',
 393		'CGettextMoFile' => '/i18n/gettext/CGettextMoFile.php',
 394		'CGettextPoFile' => '/i18n/gettext/CGettextPoFile.php',
 395		'CDbLogRoute' => '/logging/CDbLogRoute.php',
 396		'CEmailLogRoute' => '/logging/CEmailLogRoute.php',
 397		'CFileLogRoute' => '/logging/CFileLogRoute.php',
 398		'CLogFilter' => '/logging/CLogFilter.php',
 399		'CLogRoute' => '/logging/CLogRoute.php',
 400		'CLogRouter' => '/logging/CLogRouter.php',
 401		'CLogger' => '/logging/CLogger.php',
 402		'CProfileLogRoute' => '/logging/CProfileLogRoute.php',
 403		'CWebLogRoute' => '/logging/CWebLogRoute.php',
 404		'CDateTimeParser' => '/utils/CDateTimeParser.php',
 405		'CFileHelper' => '/utils/CFileHelper.php',
 406		'CFormatter' => '/utils/CFormatter.php',
 407		'CMarkdownParser' => '/utils/CMarkdownParser.php',
 408		'CPropertyValue' => '/utils/CPropertyValue.php',
 409		'CTimestamp' => '/utils/CTimestamp.php',
 410		'CVarDumper' => '/utils/CVarDumper.php',
 411		'CBooleanValidator' => '/validators/CBooleanValidator.php',
 412		'CCaptchaValidator' => '/validators/CCaptchaValidator.php',
 413		'CCompareValidator' => '/validators/CCompareValidator.php',
 414		'CDefaultValueValidator' => '/validators/CDefaultValueValidator.php',
 415		'CEmailValidator' => '/validators/CEmailValidator.php',
 416		'CExistValidator' => '/validators/CExistValidator.php',
 417		'CFileValidator' => '/validators/CFileValidator.php',
 418		'CFilterValidator' => '/validators/CFilterValidator.php',
 419		'CInlineValidator' => '/validators/CInlineValidator.php',
 420		'CNumberValidator' => '/validators/CNumberValidator.php',
 421		'CRangeValidator' => '/validators/CRangeValidator.php',
 422		'CRegularExpressionValidator' => '/validators/CRegularExpressionValidator.php',
 423		'CRequiredValidator' => '/validators/CRequiredValidator.php',
 424		'CSafeValidator' => '/validators/CSafeValidator.php',
 425		'CStringValidator' => '/validators/CStringValidator.php',
 426		'CTypeValidator' => '/validators/CTypeValidator.php',
 427		'CUniqueValidator' => '/validators/CUniqueValidator.php',
 428		'CUnsafeValidator' => '/validators/CUnsafeValidator.php',
 429		'CUrlValidator' => '/validators/CUrlValidator.php',
 430		'CValidator' => '/validators/CValidator.php',
 431		'CActiveDataProvider' => '/web/CActiveDataProvider.php',
 432		'CArrayDataProvider' => '/web/CArrayDataProvider.php',
 433		'CAssetManager' => '/web/CAssetManager.php',
 434		'CBaseController' => '/web/CBaseController.php',
 435		'CCacheHttpSession' => '/web/CCacheHttpSession.php',
 436		'CClientScript' => '/web/CClientScript.php',
 437		'CController' => '/web/CController.php',
 438		'CDataProvider' => '/web/CDataProvider.php',
 439		'CDbHttpSession' => '/web/CDbHttpSession.php',
 440		'CExtController' => '/web/CExtController.php',
 441		'CFormModel' => '/web/CFormModel.php',
 442		'CHttpCookie' => '/web/CHttpCookie.php',
 443		'CHttpRequest' => '/web/CHttpRequest.php',
 444		'CHttpSession' => '/web/CHttpSession.php',
 445		'CHttpSessionIterator' => '/web/CHttpSessionIterator.php',
 446		'COutputEvent' => '/web/COutputEvent.php',
 447		'CPagination' => '/web/CPagination.php',
 448		'CSort' => '/web/CSort.php',
 449		'CSqlDataProvider' => '/web/CSqlDataProvider.php',
 450		'CTheme' => '/web/CTheme.php',
 451		'CThemeManager' => '/web/CThemeManager.php',
 452		'CUploadedFile' => '/web/CUploadedFile.php',
 453		'CUrlManager' => '/web/CUrlManager.php',
 454		'CWebApplication' => '/web/CWebApplication.php',
 455		'CWebModule' => '/web/CWebModule.php',
 456		'CWidgetFactory' => '/web/CWidgetFactory.php',
 457		'CAction' => '/web/actions/CAction.php',
 458		'CInlineAction' => '/web/actions/CInlineAction.php',
 459		'CViewAction' => '/web/actions/CViewAction.php',
 460		'CAccessControlFilter' => '/web/auth/CAccessControlFilter.php',
 461		'CAuthAssignment' => '/web/auth/CAuthAssignment.php',
 462		'CAuthItem' => '/web/auth/CAuthItem.php',
 463		'CAuthManager' => '/web/auth/CAuthManager.php',
 464		'CBaseUserIdentity' => '/web/auth/CBaseUserIdentity.php',
 465		'CDbAuthManager' => '/web/auth/CDbAuthManager.php',
 466		'CPhpAuthManager' => '/web/auth/CPhpAuthManager.php',
 467		'CUserIdentity' => '/web/auth/CUserIdentity.php',
 468		'CWebUser' => '/web/auth/CWebUser.php',
 469		'CFilter' => '/web/filters/CFilter.php',
 470		'CFilterChain' => '/web/filters/CFilterChain.php',
 471		'CInlineFilter' => '/web/filters/CInlineFilter.php',
 472		'CForm' => '/web/form/CForm.php',
 473		'CFormButtonElement' => '/web/form/CFormButtonElement.php',
 474		'CFormElement' => '/web/form/CFormElement.php',
 475		'CFormElementCollection' => '/web/form/CFormElementCollection.php',
 476		'CFormInputElement' => '/web/form/CFormInputElement.php',
 477		'CFormStringElement' => '/web/form/CFormStringElement.php',
 478		'CGoogleApi' => '/web/helpers/CGoogleApi.php',
 479		'CHtml' => '/web/helpers/CHtml.php',
 480		'CJSON' => '/web/helpers/CJSON.php',
 481		'CJavaScript' => '/web/helpers/CJavaScript.php',
 482		'CPradoViewRenderer' => '/web/renderers/CPradoViewRenderer.php',
 483		'CViewRenderer' => '/web/renderers/CViewRenderer.php',
 484		'CWebService' => '/web/services/CWebService.php',
 485		'CWebServiceAction' => '/web/services/CWebServiceAction.php',
 486		'CWsdlGenerator' => '/web/services/CWsdlGenerator.php',
 487		'CActiveForm' => '/web/widgets/CActiveForm.php',
 488		'CAutoComplete' => '/web/widgets/CAutoComplete.php',
 489		'CClipWidget' => '/web/widgets/CClipWidget.php',
 490		'CContentDecorator' => '/web/widgets/CContentDecorator.php',
 491		'CFilterWidget' => '/web/widgets/CFilterWidget.php',
 492		'CFlexWidget' => '/web/widgets/CFlexWidget.php',
 493		'CHtmlPurifier' => '/web/widgets/CHtmlPurifier.php',
 494		'CInputWidget' => '/web/widgets/CInputWidget.php',
 495		'CMarkdown' => '/web/widgets/CMarkdown.php',
 496		'CMaskedTextField' => '/web/widgets/CMaskedTextField.php',
 497		'CMultiFileUpload' => '/web/widgets/CMultiFileUpload.php',
 498		'COutputCache' => '/web/widgets/COutputCache.php',
 499		'COutputProcessor' => '/web/widgets/COutputProcessor.php',
 500		'CStarRating' => '/web/widgets/CStarRating.php',
 501		'CTabView' => '/web/widgets/CTabView.php',
 502		'CTextHighlighter' => '/web/widgets/CTextHighlighter.php',
 503		'CTreeView' => '/web/widgets/CTreeView.php',
 504		'CWidget' => '/web/widgets/CWidget.php',
 505		'CCaptcha' => '/web/widgets/captcha/CCaptcha.php',
 506		'CCaptchaAction' => '/web/widgets/captcha/CCaptchaAction.php',
 507		'CBasePager' => '/web/widgets/pagers/CBasePager.php',
 508		'CLinkPager' => '/web/widgets/pagers/CLinkPager.php',
 509		'CListPager' => '/web/widgets/pagers/CListPager.php',
 510	);
 511}
 512spl_autoload_register(array('YiiBase','autoload'));
 513class Yii extends YiiBase
 514{
 515}
 516class CComponent
 517{
 518	private $_e;
 519	private $_m;
 520	public function __get($name)
 521	{
 522		$getter='get'.$name;
 523		if(method_exists($this,$getter))
 524			return $this->$getter();
 525		else if(strncasecmp($name,'on',2)===0 && method_exists($this,$name))
 526		{
 527			// duplicating getEventHandlers() here for performance
 528			$name=strtolower($name);
 529			if(!isset($this->_e[$name]))
 530				$this->_e[$name]=new CList;
 531			return $this->_e[$name];
 532		}
 533		else if(isset($this->_m[$name]))
 534			return $this->_m[$name];
 535		else if(is_array($this->_m))
 536		{
 537			foreach($this->_m as $object)
 538			{
 539				if($object->getEnabled() && (property_exists($object,$name) || $object->canGetProperty($name)))
 540					return $object->$name;
 541			}
 542		}
 543		throw new CException(Yii::t('yii','Property "{class}.{property}" is not defined.',
 544			array('{class}'=>get_class($this), '{property}'=>$name)));
 545	}
 546	public function __set($name,$value)
 547	{
 548		$setter='set'.$name;
 549		if(method_exists($this,$setter))
 550			return $this->$setter($value);
 551		else if(strncasecmp($name,'on',2)===0 && method_exists($this,$name))
 552		{
 553			// duplicating getEventHandlers() here for performance
 554			$name=strtolower($name);
 555			if(!isset($this->_e[$name]))
 556				$this->_e[$name]=new CList;
 557			return $this->_e[$name]->add($value);
 558		}
 559		else if(is_array($this->_m))
 560		{
 561			foreach($this->_m as $object)
 562			{
 563				if($object->getEnabled() && (property_exists($object,$name) || $object->canSetProperty($name)))
 564					return $object->$name=$value;
 565			}
 566		}
 567		if(method_exists($this,'get'.$name))
 568			throw new CException(Yii::t('yii','Property "{class}.{property}" is read only.',
 569				array('{class}'=>get_class($this), '{property}'=>$name)));
 570		else
 571			throw new CException(Yii::t('yii','Property "{class}.{property}" is not defined.',
 572				array('{class}'=>get_class($this), '{property}'=>$name)));
 573	}
 574	public function __isset($name)
 575	{
 576		$getter='get'.$name;
 577		if(method_exists($this,$getter))
 578			return $this->$getter()!==null;
 579		else if(strncasecmp($name,'on',2)===0 && method_exists($this,$name))
 580		{
 581			$name=strtolower($name);
 582			return isset($this->_e[$name]) && $this->_e[$name]->getCount();
 583		}
 584		else if(is_array($this->_m))
 585		{
 586 			if(isset($this->_m[$name]))
 587 				return true;
 588			foreach($this->_m as $object)
 589			{
 590				if($object->getEnabled() && (property_exists($object,$name) || $object->canGetProperty($name)))
 591					return true;
 592			}
 593		}
 594		return false;
 595	}
 596	public function __unset($name)
 597	{
 598		$setter='set'.$name;
 599		if(method_exists($this,$setter))
 600			$this->$setter(null);
 601		else if(strncasecmp($name,'on',2)===0 && method_exists($this,$name))
 602			unset($this->_e[strtolower($name)]);
 603		else if(is_array($this->_m))
 604		{
 605			if(isset($this->_m[$name]))
 606				$this->detachBehavior($name);
 607			else
 608			{
 609				foreach($this->_m as $object)
 610				{
 611					if($object->getEnabled())
 612					{
 613						if(property_exists($object,$name))
 614							return $object->$name=null;
 615						else if($object->canSetProperty($name))
 616							return $object->$setter(null);
 617					}
 618				}
 619			}
 620		}
 621		else if(method_exists($this,'get'.$name))
 622			throw new CException(Yii::t('yii','Property "{class}.{property}" is read only.',
 623				array('{class}'=>get_class($this), '{property}'=>$name)));
 624	}
 625	public function __call($name,$parameters)
 626	{
 627		if($this->_m!==null)
 628		{
 629			foreach($this->_m as $object)
 630			{
 631				if($object->getEnabled() && method_exists($object,$name))
 632					return call_user_func_array(array($object,$name),$parameters);
 633			}
 634		}
 635		if(class_exists('Closure', false) && $this->$name instanceof Closure)
 636			return call_user_func_array($this->$name, $parameters);
 637		throw new CException(Yii::t('yii','{class} does not have a method named "{name}".',
 638			array('{class}'=>get_class($this), '{name}'=>$name)));
 639	}
 640	public function asa($behavior)
 641	{
 642		return isset($this->_m[$behavior]) ? $this->_m[$behavior] : null;
 643	}
 644	public function attachBehaviors($behaviors)
 645	{
 646		foreach($behaviors as $name=>$behavior)
 647			$this->attachBehavior($name,$behavior);
 648	}
 649	public function detachBehaviors()
 650	{
 651		if($this->_m!==null)
 652		{
 653			foreach($this->_m as $name=>$behavior)
 654				$this->detachBehavior($name);
 655			$this->_m=null;
 656		}
 657	}
 658	public function attachBehavior($name,$behavior)
 659	{
 660		if(!($behavior instanceof IBehavior))
 661			$behavior=Yii::createComponent($behavior);
 662		$behavior->setEnabled(true);
 663		$behavior->attach($this);
 664		return $this->_m[$name]=$behavior;
 665	}
 666	public function detachBehavior($name)
 667	{
 668		if(isset($this->_m[$name]))
 669		{
 670			$this->_m[$name]->detach($this);
 671			$behavior=$this->_m[$name];
 672			unset($this->_m[$name]);
 673			return $behavior;
 674		}
 675	}
 676	public function enableBehaviors()
 677	{
 678		if($this->_m!==null)
 679		{
 680			foreach($this->_m as $behavior)
 681				$behavior->setEnabled(true);
 682		}
 683	}
 684	public function disableBehaviors()
 685	{
 686		if($this->_m!==null)
 687		{
 688			foreach($this->_m as $behavior)
 689				$behavior->setEnabled(false);
 690		}
 691	}
 692	public function enableBehavior($name)
 693	{
 694		if(isset($this->_m[$name]))
 695			$this->_m[$name]->setEnabled(true);
 696	}
 697	public function disableBehavior($name)
 698	{
 699		if(isset($this->_m[$name]))
 700			$this->_m[$name]->setEnabled(false);
 701	}
 702	public function hasProperty($name)
 703	{
 704		return method_exists($this,'get'.$name) || method_exists($this,'set'.$name);
 705	}
 706	public function canGetProperty($name)
 707	{
 708		return method_exists($this,'get'.$name);
 709	}
 710	public function canSetProperty($name)
 711	{
 712		return method_exists($this,'set'.$name);
 713	}
 714	public function hasEvent($name)
 715	{
 716		return !strncasecmp($name,'on',2) && method_exists($this,$name);
 717	}
 718	public function hasEventHandler($name)
 719	{
 720		$name=strtolower($name);
 721		return isset($this->_e[$name]) && $this->_e[$name]->getCount()>0;
 722	}
 723	public function getEventHandlers($name)
 724	{
 725		if($this->hasEvent($name))
 726		{
 727			$name=strtolower($name);
 728			if(!isset($this->_e[$name]))
 729				$this->_e[$name]=new CList;
 730			return $this->_e[$name];
 731		}
 732		else
 733			throw new CException(Yii::t('yii','Event "{class}.{event}" is not defined.',
 734				array('{class}'=>get_class($this), '{event}'=>$name)));
 735	}
 736	public function attachEventHandler($name,$handler)
 737	{
 738		$this->getEventHandlers($name)->add($handler);
 739	}
 740	public function detachEventHandler($name,$handler)
 741	{
 742		if($this->hasEventHandler($name))
 743			return $this->getEventHandlers($name)->remove($handler)!==false;
 744		else
 745			return false;
 746	}
 747	public function raiseEvent($name,$event)
 748	{
 749		$name=strtolower($name);
 750		if(isset($this->_e[$name]))
 751		{
 752			foreach($this->_e[$name] as $handler)
 753			{
 754				if(is_string($handler))
 755					call_user_func($handler,$event);
 756				else if(is_callable($handler,true))
 757				{
 758					if(is_array($handler))
 759					{
 760						// an array: 0 - object, 1 - method name
 761						list($object,$method)=$handler;
 762						if(is_string($object))	// static method call
 763							call_user_func($handler,$event);
 764						else if(method_exists($object,$method))
 765							$object->$method($event);
 766						else
 767							throw new CException(Yii::t('yii','Event "{class}.{event}" is attached with an invalid handler "{handler}".',
 768								array('{class}'=>get_class($this), '{event}'=>$name, '{handler}'=>$handler[1])));
 769					}
 770					else // PHP 5.3: anonymous function
 771						call_user_func($handler,$event);
 772				}
 773				else
 774					throw new CException(Yii::t('yii','Event "{class}.{event}" is attached with an invalid handler "{handler}".',
 775						array('{class}'=>get_class($this), '{event}'=>$name, '{handler}'=>gettype($handler))));
 776				// stop further handling if param.handled is set true
 777				if(($event instanceof CEvent) && $event->handled)
 778					return;
 779			}
 780		}
 781		else if(YII_DEBUG && !$this->hasEvent($name))
 782			throw new CException(Yii::t('yii','Event "{class}.{event}" is not defined.',
 783				array('{class}'=>get_class($this), '{event}'=>$name)));
 784	}
 785	public function evaluateExpression($_expression_,$_data_=array())
 786	{
 787		if(is_string($_expression_))
 788		{
 789			extract($_data_);
 790			return eval('return '.$_expression_.';');
 791		}
 792		else
 793		{
 794			$_data_[]=$this;
 795			return call_user_func_array($_expression_, $_data_);
 796		}
 797	}
 798}
 799class CEvent extends CComponent
 800{
 801	public $sender;
 802	public $handled=false;
 803	public function __construct($sender=null)
 804	{
 805		$this->sender=$sender;
 806	}
 807}
 808class CEnumerable
 809{
 810}
 811abstract class CModule extends CComponent
 812{
 813	public $preload=array();
 814	public $behaviors=array();
 815	private $_id;
 816	private $_parentModule;
 817	private $_basePath;
 818	private $_modulePath;
 819	private $_params;
 820	private $_modules=array();
 821	private $_moduleConfig=array();
 822	private $_components=array();
 823	private $_componentConfig=array();
 824	public function __construct($id,$parent,$config=null)
 825	{
 826		$this->_id=$id;
 827		$this->_parentModule=$parent;
 828		// set basePath at early as possible to avoid trouble
 829		if(is_string($config))
 830			$config=require($config);
 831		if(isset($config['basePath']))
 832		{
 833			$this->setBasePath($config['basePath']);
 834			unset($config['basePath']);
 835		}
 836		Yii::setPathOfAlias($id,$this->getBasePath());
 837		$this->preinit();
 838		$this->configure($config);
 839		$this->attachBehaviors($this->behaviors);
 840		$this->preloadComponents();
 841		$this->init();
 842	}
 843	public function __get($name)
 844	{
 845		if($this->hasComponent($name))
 846			return $this->getComponent($name);
 847		else
 848			return parent::__get($name);
 849	}
 850	public function __isset($name)
 851	{
 852		if($this->hasComponent($name))
 853			return $this->getComponent($name)!==null;
 854		else
 855			return parent::__isset($name);
 856	}
 857	public function getId()
 858	{
 859		return $this->_id;
 860	}
 861	public function setId($id)
 862	{
 863		$this->_id=$id;
 864	}
 865	public function getBasePath()
 866	{
 867		if($this->_basePath===null)
 868		{
 869			$class=new ReflectionClass(get_class($this));
 870			$this->_basePath=dirname($class->getFileName());
 871		}
 872		return $this->_basePath;
 873	}
 874	public function setBasePath($path)
 875	{
 876		if(($this->_basePath=realpath($path))===false || !is_dir($this->_basePath))
 877			throw new CException(Yii::t('yii','Base path "{path}" is not a valid directory.',
 878				array('{path}'=>$path)));
 879	}
 880	public function getParams()
 881	{
 882		if($this->_params!==null)
 883			return $this->_params;
 884		else
 885		{
 886			$this->_params=new CAttributeCollection;
 887			$this->_params->caseSensitive=true;
 888			return $this->_params;
 889		}
 890	}
 891	public function setParams($value)
 892	{
 893		$params=$this->getParams();
 894		foreach($value as $k=>$v)
 895			$params->add($k,$v);
 896	}
 897	public function getModulePath()
 898	{
 899		if($this->_modulePath!==null)
 900			return $this->_modulePath;
 901		else
 902			return $this->_modulePath=$this->getBasePath().DIRECTORY_SEPARATOR.'modules';
 903	}
 904	public function setModulePath($value)
 905	{
 906		if(($this->_modulePath=realpath($value))===false || !is_dir($this->_modulePath))
 907			throw new CException(Yii::t('yii','The module path "{path}" is not a valid directory.',
 908				array('{path}'=>$value)));
 909	}
 910	public function setImport($aliases)
 911	{
 912		foreach($aliases as $alias)
 913			Yii::import($alias);
 914	}
 915	public function setAliases($mappings)
 916	{
 917		foreach($mappings as $name=>$alias)
 918		{
 919			if(($path=Yii::getPathOfAlias($alias))!==false)
 920				Yii::setPathOfAlias($name,$path);
 921			else
 922				Yii::setPathOfAlias($name,$alias);
 923		}
 924	}
 925	public function getParentModule()
 926	{
 927		return $this->_parentModule;
 928	}
 929	public function getModule($id)
 930	{
 931		if(isset($this->_modules[$id]) || array_key_exists($id,$this->_modules))
 932			return $this->_modules[$id];
 933		else if(isset($this->_moduleConfig[$id]))
 934		{
 935			$config=$this->_moduleConfig[$id];
 936			if(!isset($config['enabled']) || $config['enabled'])
 937			{
 938				$class=$config['class'];
 939				unset($config['class'], $config['enabled']);
 940				if($this===Yii::app())
 941					$module=Yii::createComponent($class,$id,null,$config);
 942				else
 943					$module=Yii::createComponent($class,$this->getId().'/'.$id,$this,$config);
 944				return $this->_modules[$id]=$module;
 945			}
 946		}
 947	}
 948	public function hasModule($id)
 949	{
 950		return isset($this->_moduleConfig[$id]) || isset($this->_modules[$id]);
 951	}
 952	public function getModules()
 953	{
 954		return $this->_moduleConfig;
 955	}
 956	public function setModules($modules)
 957	{
 958		foreach($modules as $id=>$module)
 959		{
 960			if(is_int($id))
 961			{
 962				$id=$module;
 963				$module=array();
 964			}
 965			if(!isset($module['class']))
 966			{
 967				Yii::setPathOfAlias($id,$this->getModulePath().DIRECTORY_SEPARATOR.$id);
 968				$module['class']=$id.'.'.ucfirst($id).'Module';
 969			}
 970			if(isset($this->_moduleConfig[$id]))
 971				$this->_moduleConfig[$id]=CMap::mergeArray($this->_moduleConfig[$id],$module);
 972			else
 973				$this->_moduleConfig[$id]=$module;
 974		}
 975	}
 976	public function hasComponent($id)
 977	{
 978		return isset($this->_components[$id]) || isset($this->_componentConfig[$id]);
 979	}
 980	public function getComponent($id,$createIfNull=true)
 981	{
 982		if(isset($this->_components[$id]))
 983			return $this->_components[$id];
 984		else if(isset($this->_componentConfig[$id]) && $createIfNull)
 985		{
 986			$config=$this->_componentConfig[$id];
 987			if(!isset($config['enabled']) || $config['enabled'])
 988			{
 989				unset($config['enabled']);
 990				$component=Yii::createComponent($config);
 991				$component->init();
 992				return $this->_components[$id]=$component;
 993			}
 994		}
 995	}
 996	public function setComponent($id,$component)
 997	{
 998		if($component===null)
 999			unset($this->_components[$id]);
1000		else
1001		{
1002			$this->_components[$id]=$component;
1003			if(!$component->getIsInitialized())
1004				$component->init();
1005		}
1006	}
1007	public function getComponents($loadedOnly=true)
1008	{
1009		if($loadedOnly)
1010			return $this->_components;
1011		else
1012			return array_merge($this->_componentConfig, $this->_components);
1013	}
1014	public function setComponents($components,$merge=true)
1015	{
1016		foreach($components as $id=>$component)
1017		{
1018			if($component instanceof IApplicationComponent)
1019				$this->setComponent($id,$component);
1020			else if(isset($this->_componentConfig[$id]) && $merge)
1021				$this->_componentConfig[$id]=CMap::mergeArray($this->_componentConfig[$id],$component);
1022			else
1023				$this->_componentConfig[$id]=$component;
1024		}
1025	}
1026	public function configure($config)
1027	{
1028		if(is_array($config))
1029		{
1030			foreach($config as $key=>$value)
1031				$this->$key=$value;
1032		}
1033	}
1034	protected function preloadComponents()
1035	{
1036		foreach($this->preload as $id)
1037			$this->getComponent($id);
1038	}
1039	protected function preinit()
1040	{
1041	}
1042	protected function init()
1043	{
1044	}
1045}
1046abstract class CApplication extends CModule
1047{
1048	public $name='My Application';
1049	public $charset='UTF-8';
1050	public $sourceLanguage='en_us';
1051	private $_id;
1052	private $_basePath;
1053	private $_runtimePath;
1054	private $_extensionPath;
1055	private $_globalState;
1056	private $_stateChanged;
1057	private $_ended=false;
1058	private $_language;
1059	abstract public function processRequest();
1060	public function __construct($config=null)
1061	{
1062		Yii::setApplication($this);
1063		// set basePath at early as possible to avoid trouble
1064		if(is_string($config))
1065			$config=require($config);
1066		if(isset($config['basePath']))
1067		{
1068			$this->setBasePath($config['basePath']);
1069			unset($config['basePath']);
1070		}
1071		else
1072			$this->setBasePath('protected');
1073		Yii::setPathOfAlias('application',$this->getBasePath());
1074		Yii::setPathOfAlias('webroot',dirname($_SERVER['SCRIPT_FILENAME']));
1075		Yii::setPathOfAlias('ext',$this->getBasePath().DIRECTORY_SEPARATOR.'extensions');
1076		$this->preinit();
1077		$this->initSystemHandlers();
1078		$this->registerCoreComponents();
1079		$this->configure($config);
1080		$this->attachBehaviors($this->behaviors);
1081		$this->preloadComponents();
1082		$this->init();
1083	}
1084	public function run()
1085	{
1086		if($this->hasEventHandler('onBeginRequest'))
1087			$this->onBeginRequest(new CEvent($this));
1088		$this->processRequest();
1089		if($this->hasEventHandler('onEndRequest'))
1090			$this->onEndRequest(new CEvent($this));
1091	}
1092	public function end($status=0, $exit=true)
1093	{
1094		if($this->hasEventHandler('onEndRequest'))
1095			$this->onEndRequest(new CEvent($this));
1096		if($exit)
1097			exit($status);
1098	}
1099	public function onBeginRequest($event)
1100	{
1101		$this->raiseEvent('onBeginRequest',$event);
1102	}
1103	public function onEndRequest($event)
1104	{
1105		if(!$this->_ended)
1106		{
1107			$this->_ended=true;
1108			$this->raiseEvent('onEndRequest',$event);
1109		}
1110	}
1111	public function getId()
1112	{
1113		if($this->_id!==null)
1114			return $this->_id;
1115		else
1116			return $this->_id=sprintf('%x',crc32($this->getBasePath().$this->name));
1117	}
1118	public function setId($id)
1119	{
1120		$this->_id=$id;
1121	}
1122	public function getBasePath()
1123	{
1124		return $this->_basePath;
1125	}
1126	public function setBasePath($path)
1127	{
1128		if(($this->_basePath=realpath($path))===false || !is_dir($this->_basePath))
1129			throw new CException(Yii::t('yii','Application base path "{path}" is not a valid directory.',
1130				array('{path}'=>$path)));
1131	}
1132	public function getRuntimePath()
1133	{
1134		if($this->_runtimePath!==null)
1135			return $this->_runtimePath;
1136		else
1137		{
1138			$this->setRuntimePath($this->getBasePath().DIRECTORY_SEPARATOR.'runtime');
1139			return $this->_runtimePath;
1140		}
1141	}
1142	public function setRuntimePath($path)
1143	{
1144		if(($runtimePath=realpath($path))===false || !is_dir($runtimePath) || !is_writable($runtimePath))
1145			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.',
1146				array('{path}'=>$path)));
1147		$this->_runtimePath=$runtimePath;
1148	}
1149	public function getExtensionPath()
1150	{
1151		return Yii::getPathOfAlias('ext');
1152	}
1153	public function setExtensionPath($path)
1154	{
1155		if(($extensionPath=realpath($path))===false || !is_dir($extensionPath))
1156			throw new CException(Yii::t('yii','Extension path "{path}" does not exist.',
1157				array('{path}'=>$path)));
1158		Yii::setPathOfAlias('ext',$extensionPath);
1159	}
1160	public function getLanguage()
1161	{
1162		return $this->_language===null ? $this->sourceLanguage : $this->_language;
1163	}
1164	public function setLanguage($language)
1165	{
1166		$this->_language=$language;
1167	}
1168	public function getTimeZone()
1169	{
1170		return date_default_timezone_get();
1171	}
1172	public function setTimeZone($value)
1173	{
1174		date_default_timezone_set($value);
1175	}
1176	public function findLocalizedFile($srcFile,$srcLanguage=null,$language=null)
1177	{
1178		if($srcLanguage===null)
1179			$srcLanguage=$this->sourceLanguage;
1180		if($language===null)
1181			$language=$this->getLanguage();
1182		if($language===$srcLanguage)
1183			return $srcFile;
1184		$desiredFile=dirname($srcFile).DIRECTORY_SEPARATOR.$language.DIRECTORY_SEPARATOR.basename($srcFile);
1185		return is_file($desiredFile) ? $desiredFile : $srcFile;
1186	}
1187	public function getLocale($localeID=null)
1188	{
1189		return CLocale::getInstance($localeID===null?$this->getLanguage():$localeID);
1190	}
1191	public function getLocaleDataPath()
1192	{
1193		return CLocale::$dataPath===null ? Yii::getPathOfAlias('system.i18n.data') : CLocale::$dataPath;
1194	}
1195	public function setLocaleDataPath($value)
1196	{
1197		CLocale::$dataPath=$value;
1198	}
1199	public function getNumberFormatter()
1200	{
1201		return $this->getLocale()->getNumberFormatter();
1202	}
1203	public function getDateFormatter()
1204	{
1205		return $this->getLocale()->getDateFormatter();
1206	}
1207	public function getDb()
1208	{
1209		return $this->getComponent('db');
1210	}
1211	public function getErrorHandler()
1212	{
1213		return $this->getComponent('errorHandler');
1214	}
1215	public function getSecurityManager()
1216	{
1217		return $this->getComponent('securityManager');
1218	}
1219	public function getStatePersister()
1220	{
1221		return $this->getComponent('statePersister');
1222	}
1223	public function getCache()
1224	{
1225		return $this->getComponent('cache');
1226	}
1227	public function getCoreMessages()
1228	{
1229		return $this->getComponent('coreMessages');
1230	}
1231	public function getMessages()
1232	{
1233		return $this->getComponent('messages');
1234	}
1235	public function getRequest()
1236	{
1237		return $this->getComponent('request');
1238	}
1239	public function getUrlManager()
1240	{
1241		return $this->getComponent('urlManager');
1242	}
1243	public function getGlobalState($key,$defaultValue=null)
1244	{
1245		if($this->_globalState===null)
1246			$this->loadGlobalState();
1247		if(isset($this->_globalState[$key]))
1248			return $this->_globalState[$key];
1249		else
1250			return $defaultValue;
1251	}
1252	public function setGlobalState($key,$value,$defaultValue=null)
1253	{
1254		if($this->_globalState===null)
1255			$this->loadGlobalState();
1256		$changed=$this->_stateChanged;
1257		if($value===$defaultValue)
1258		{
1259			if(isset($this->_globalState[$key]))
1260			{
1261				unset($this->_globalState[$key]);
1262				$this->_stateChanged=true;
1263			}
1264		}
1265		else if(!isset($this->_globalState[$key]) || $this->_globalState[$key]!==$value)
1266		{
1267			$this->_globalState[$key]=$value;
1268			$this->_stateChanged=true;
1269		}
1270		if($this->_stateChanged!==$changed)
1271			$this->attachEventHandler('onEndRequest',array($this,'saveGlobalState'));
1272	}
1273	public function clearGlobalState($key)
1274	{
1275		$this->setGlobalState($key,true,true);
1276	}
1277	public function loadGlobalState()
1278	{
1279		$persister=$this->getStatePersister();
1280		if(($this->_globalState=$persister->load())===null)
1281			$this->_globalState=array();
1282		$this->_stateChanged=false;
1283		$this->detachEventHandler('onEndRequest',array($this,'saveGlobalState'));
1284	}
1285	public function saveGlobalState()
1286	{
1287		if($this->_stateChanged)
1288		{
1289			$this->_stateChanged=false;
1290			$this->detachEventHandler('onEndRequest',array($this,'saveGlobalState'));
1291			$this->getStatePersister()->save($this->_globalState);
1292		}
1293	}
1294	public function handleException($exception)
1295	{
1296		// disable error capturing to avoid recursive errors
1297		restore_error_handler();
1298		restore_exception_handler();
1299		$category='exception.'.get_class($exception);
1300		if($exception instanceof CHttpException)
1301			$category.='.'.$exception->statusCode;
1302		// php <5.2 doesn't support string conversion auto-magically
1303		$message=$exception->__toString();
1304		if(isset($_SERVER['REQUEST_URI']))
1305			$message.=' REQUEST_URI='.$_SERVER['REQUEST_URI'];
1306		Yii::log($message,CLogger::LEVEL_ERROR,$category);
1307		try
1308		{
1309			$event=new CExceptionEvent($this,$exception);
1310			$this->onException($event);
1311			if(!$event->handled)
1312			{
1313				// try an error handler
1314				if(($handler=$this->getErrorHandler())!==null)
1315					$handler->handle($event);
1316				else
1317					$this->displayException($exception);
1318			}
1319		}
1320		catch(Exception $e)
1321		{
1322			$this->displayException($e);
1323		}
1324		try
1325		{
1326			$this->end(1);
1327		}
1328		catch(Exception $e)
1329		{
1330			// use the most primitive way to log error
1331			$msg = get_class($e).': '.$e->getMessage().' ('.$e->getFile().':'.$e->getLine().")\n";
1332			$msg .= $e->getTraceAsString()."\n";
1333			$msg .= "Previous exception:\n";
1334			$msg .= get_class($exception).': '.$exception->getMessage().' ('.$exception->getFile().':'.$exception->getLine().")\n";
1335			$msg .= $exception->getTraceAsString()."\n";
1336			$msg .= '$_SERVER='.var_export($_SERVER,true);
1337			error_log($msg);
1338			exit(1);
1339		}
1340	}
1341	public function handleError($code,$message,$file,$line)
1342	{
1343		if($code & error_reporting())
1344		{
1345			// disable error capturing to avoid recursive errors
1346			restore_error_handler();
1347			restore_exception_handler();
1348			$log="$message ($file:$line)\nStack trace:\n";
1349			$trace=debug_backtrace();
1350			// skip the first 3 stacks as they do not tell the error position
1351			if(count($trace)>3)
1352				$trace=array_slice($trace,3);
1353			foreach($trace as $i=>$t)
1354			{
1355				if(!isset($t['file']))
1356					$t['file']='unknown';
1357				if(!isset($t['line']))
1358					$t['line']=0;
1359				if(!isset($t['function']))
1360					$t['function']='unknown';
1361				$log.="#$i {$t['file']}({$t['line']}): ";
1362				if(isset($t['object']) && is_object($t['object']))
1363					$log.=get_class($t['object']).'->';
1364				$log.="{$t['function']}()\n";
1365			}
1366			if(isset($_SERVER['REQUEST_URI']))
1367				$log.='REQUEST_URI='.$_SERVER['REQUEST_URI'];
1368			Yii::log($log,CLogger::LEVEL_ERROR,'php');
1369			try
1370			{
1371				Yii::import('CErrorEvent',true);
1372				$event=new CErrorEvent($this,$code,$message,$file,$line);
1373				$this->onError($event);
1374				if(!$event->handled)
1375				{
1376					// try an error handler
1377					if(($handler=$this->getErrorHandler())!==null)
1378						$handler->handle($event);
1379					else
1380						$this->displayError($code,$message,$file,$line);
1381				}
1382			}
1383			catch(Exception $e)
1384			{
1385				$this->displayException($e);
1386			}
1387			try
1388			{
1389				$this->end(1);
1390			}
1391			catch(Exception $e)
1392			{
1393				// use the most primitive way to log error
1394				$msg = get_class($e).': '.$e->getMessage().' ('.$e->getFile().':'.$e->getLine().")\n";
1395				$msg .= $e->getTraceAsString()."\n";
1396				$msg .= "Previous error:\n";
1397				$msg .= $log."\n";
1398				$msg .= '$_SERVER='.var_export($_SERVER,true);
1399				error_log($msg);
1400				exit(1);
1401			}
1402		}
1403	}
1404	public function onException($event)
1405	{
1406		$this->raiseEvent('onException',$event);
1407	}
1408	public function onError($event)
1409	{
1410		$this->raiseEvent('onError',$event);
1411	}
1412	public function displayError($code,$message,$file,$line)
1413	{
1414		if(YII_DEBUG)
1415		{
1416			echo "<h1>PHP Error [$code]</h1>\n";
1417			echo "<p>$message ($file:$line)</p>\n";
1418			echo '<pre>';
1419			$trace=debug_backtrace();
1420			// skip the first 3 stacks as they do not tell the error position
1421			if(count($trace)>3)
1422				$trace=array_slice($trace,3);
1423			foreach($trace as $i=>$t)
1424			{
1425				if(!isset($t['file']))
1426					$t['file']='unknown';
1427				if(!isset($t['line']))
1428					$t['line']=0;
1429				if(!isset($t['function']))
1430					$t['function']='unknown';
1431				echo "#$i {$t['file']}({$t['line']}): ";
1432				if(isset($t['object']) && is_object($t['object']))
1433					echo get_class($t['object']).'->';
1434				echo "{$t['function']}()\n";
1435			}
1436			echo '</pre>';
1437		}
1438		else
1439		{
1440			echo "<h1>PHP Error [$code]</h1>\n";
1441			echo "<p>$message</p>\n";
1442		}
1443	}
1444	public function displayException($exception)
1445	{
1446		if(YII_DEBUG)
1447		{
1448			echo '<h1>'.get_class($exception)."</h1>\n";
1449			echo '<p>'.$exception->getMessage().' ('.$exception->getFile().':'.$exception->getLine().')</p>';
1450			echo '<pre>'.$exception->getTraceAsString().'</pre>';
1451		}
1452		else
1453		{
1454			echo '<h1>'.get_class($exception)."</h1>\n";
1455			echo '<p>'.$exception->getMessage().'</p>';
1456		}
1457	}
1458	protected function initSystemHandlers()
1459	{
1460		if(YII_ENABLE_EXCEPTION_HANDLER)
1461			set_exception_handler(array($this,'handleException'));
1462		if(YII_ENABLE_ERROR_HANDLER)
1463			set_error_handler(array($this,'handleError'),error_reporting());
1464	}
1465	protected function registerCoreComponents()
1466	{
1467		$components=array(
1468			'coreMessages'=>array(
1469				'class'=>'CPhpMessageSource',
1470				'language'=>'en_us',
1471				'basePath'=>YII_PATH.DIRECTORY_SEPARATOR.'messages',
1472			),
1473			'db'=>array(
1474				'class'=>'CDbConnection',
1475			),
1476			'messages'=>array(
1477				'class'=>'CPhpMessageSource',
1478			),
1479			'errorHandler'=>array(
1480				'class'=>'CErrorHandler',
1481			),
1482			'securityManager'=>array(
1483				'class'=>'CSecurityManager',
1484			),
1485			'statePersister'=>array(
1486				'class'=>'CStatePersister',
1487			),
1488			'urlManager'=>array(
1489				'class'=>'CUrlManager',
1490			),
1491			'request'=>array(
1492				'class'=>'CHttpRequest',
1493			),
1494			'format'=>array(
1495				'class'=>'CFormatter',
1496			),
1497		);
1498		$this->setComponents($components);
1499	}
1500}
1501class CWebApplication extends CApplication
1502{
1503	public $defaultController='site';
1504	public $layout='main';
1505	public $controllerMap=array();
1506	public $catchAllRequest;
1507	private $_controllerPath;
1508	private $_viewPath;
1509	private $_systemViewPath;
1510	private $_layoutPath;
1511	private $_controller;
1512	private $_homeUrl;
1513	private $_theme;
1514	public function processRequest()
1515	{
1516		if(is_array($this->catchAllRequest) && isset($this->catchAllRequest[0]))
1517		{
1518			$route=$this->catchAllRequest[0];
1519			foreach(array_splice($this->catchAllRequest,1) as $name=>$value)
1520				$_GET[$name]=$value;
1521		}
1522		else
1523			$route=$this->getUrlManager()->parseUrl($this->getRequest());
1524		$this->runController($route);
1525	}
1526	protected function registerCoreComponents()
1527	{
1528		parent::registerCoreComponents();
1529		$components=array(
1530			'session'=>array(
1531				'class'=>'CHttpSession',
1532			),
1533			'assetManager'=>array(
1534				'class'=>'CAssetManager',
1535			),
1536			'user'=>array(
1537				'class'=>'CWebUser',
1538			),
1539			'themeManager'=>array(
1540				'class'=>'CThemeManager',
1541			),
1542			'authManager'=>array(
1543				'class'=>'CPhpAuthManager',
1544			),
1545			'clientScript'=>array(
1546				'class'=>'CClientScript',
1547			),
1548			'widgetFactory'=>array(
1549				'class'=>'CWidgetFactory',
1550			),
1551		);
1552		$this->setComponents($components);
1553	}
1554	public function getAuthManager()
1555	{
1556		return $this->getComponent('authManager');
1557	}
1558	public function getAssetManager()
1559	{
1560		return $this->getComponent('assetManager');
1561	}
1562	public function getSession()
1563	{
1564		return $this->getComponent('session');
1565	}
1566	public function getUser()
1567	{
1568		return $this->getComponent('user');
1569	}
1570	public function getViewRenderer()
1571	{
1572		return $this->getComponent('viewRenderer');
1573	}
1574	public function getClientScript()
1575	{
1576		return $this->getComponent('clientScript');
1577	}
1578	public function getWidgetFactory()
1579	{
1580		return $this->getComponent('widgetFactory');
1581	}
1582	public function getThemeManager()
1583	{
1584		return $this->getComponent('themeManager');
1585	}
1586	public function getTheme()
1587	{
1588		if(is_string($this->_theme))
1589			$this->_theme=$this->getThemeManager()->getTheme($this->_theme);
1590		return $this->_theme;
1591	}
1592	public function setTheme($value)
1593	{
1594		$this->_theme=$value;
1595	}
1596	public function createUrl($route,$params=array(),$ampersand='&')
1597	{
1598		return $this->getUrlManager()->createUrl($route,$params,$ampersand);
1599	}
1600	public function createAbsoluteUrl($route,$params=array(),$schema='',$ampersand='&')
1601	{
1602		return $this->getRequest()->getHostInfo($schema).$this->createUrl($route,$params,$ampersand);
1603	}
1604	public function getBaseUrl($absolute=false)
1605	{
1606		return $this->getRequest()->getBaseUrl($absolute);
1607	}
1608	public function getHomeUrl()
1609	{
1610		if($this->_homeUrl===null)
1611		{
1612			if($this->getUrlManager()->showScriptName)
1613				return $this->getRequest()->getScriptUrl();
1614			else
1615				return $this->getRequest()->getBaseUrl().'/';
1616		}
1617		else
1618			return $this->_homeUrl;
1619	}
1620	public function setHomeUrl($value)
1621	{
1622		$this->_homeUrl=$value;
1623	

Large files files are truncated, but you can click here to view the full file