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

/yii/framework/yiilite.php

https://bitbucket.org/ddonthula/zurmoreporting
PHP | 10023 lines | 9966 code | 2 blank | 55 comment | 707 complexity | 9f23d140de371469908a3c3fab54062e MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, GPL-2.0, GPL-3.0, BSD-3-Clause, LGPL-3.0

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

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