PageRenderTime 74ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 1ms

/framework/yiilite.php

https://bitbucket.org/21h/torchok-anon
PHP | 9013 lines | 8958 code | 2 blank | 53 comment | 753 complexity | 686ebec729c2bae2bd6433419f56228f MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, BSD-2-Clause

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

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

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