PageRenderTime 979ms CodeModel.GetById 182ms app.highlight 365ms RepoModel.GetById 177ms app.codeStats 5ms

/framework/yiilite.php

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

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