PageRenderTime 63ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 2ms

/yii/framework/yiilite.php

https://github.com/ashie1287/headfirst
PHP | 8222 lines | 8169 code | 2 blank | 51 comment | 759 complexity | 9152398444fbb3c4a5014c14c3929aec MD5 | raw file
Possible License(s): BSD-2-Clause, BSD-3-Clause, LGPL-2.1

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

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