PageRenderTime 53ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 1ms

/framework/yiilite.php

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

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