PageRenderTime 27ms CodeModel.GetById 8ms app.highlight 78ms RepoModel.GetById 2ms app.codeStats 3ms

/framework/yiilite.php

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

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