PageRenderTime 66ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/yii/yiilite.php

https://bitbucket.org/Crisu83/webgames
PHP | 9678 lines | 9623 code | 2 blank | 53 comment | 815 complexity | 47ae14a1de722724e4bdc61582da7a41 MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0, GPL-3.0, LGPL-2.0, LGPL-2.1, BSD-2-Clause

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

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