PageRenderTime 105ms CodeModel.GetById 21ms app.highlight 41ms RepoModel.GetById 15ms app.codeStats 2ms

/framework/yiilite.php

https://github.com/balor/yiicms
PHP | 7435 lines | 7386 code | 2 blank | 47 comment | 636 complexity | 42c49d4d97e93768bb631e06465e2df0 MD5 | raw file

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

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

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