PageRenderTime 68ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 1ms

/yii/yiilite.php

https://bitbucket.org/bongnv_53/se2010-n1
PHP | 8430 lines | 8376 code | 2 blank | 52 comment | 747 complexity | 144f4d961afd3275323903e9bd527175 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, BSD-2-Clause

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

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

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