PageRenderTime 68ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 2ms

/yii/framework/yiilite.php

https://bitbucket.org/Amit_Ashckenazi/unmatched-archives
PHP | 9814 lines | 9762 code | 2 blank | 50 comment | 742 complexity | 9520e0fa165bc53602c506c99869d23d MD5 | raw file
Possible License(s): GPL-3.0, BSD-3-Clause, LGPL-3.0, LGPL-2.1, BSD-2-Clause

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

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

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