PageRenderTime 67ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

/framework/yiilite.php

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

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