Application.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace Qii;
  3. use \Qii\Autoloader;
  4. /**
  5. * Qii 框架基本库所在路径
  6. */
  7. define('Qii_DIR', dirname(__FILE__));
  8. /**
  9. * DIRECTORY_SEPARATOR 的简写
  10. */
  11. define('DS', DIRECTORY_SEPARATOR);
  12. /**
  13. * 定义包含的路径分隔符
  14. */
  15. define('PS', PATH_SEPARATOR);
  16. /**
  17. * 定义操作系统类型
  18. */
  19. define('OS', strtoupper(substr(PHP_OS, 0, 3)));
  20. define('IS_CLI', php_sapi_name() == 'cli' ? true : false);
  21. include(Qii_DIR . DS .'Autoloader'. DS . 'Factory.php');
  22. include(Qii_DIR . DS .'Config'. DS . 'Arrays.php');
  23. class Application
  24. {
  25. /**
  26. * 存储网站配置文件内容
  27. *
  28. * @var array $_config 配置内容
  29. */
  30. protected static $_config = [];
  31. public function __construct()
  32. {
  33. }
  34. /**
  35. * 初始化本实例对象
  36. *
  37. * @return object
  38. */
  39. public static function getInstance()
  40. {
  41. return \Qii\Autoloader\Factory::getInstance('\Qii\Application');
  42. }
  43. /**
  44. * 设置网站配置文件
  45. *
  46. * @param array $config 配置文件
  47. */
  48. public function setConfig($config = [])
  49. {
  50. \Qii\Autoloader\Factory::getInstance('\Qii\Config\Arrays')
  51. ->set('Application', $config);
  52. }
  53. /**
  54. * 获取指定配置内容key的值
  55. *
  56. * @param string $key 配置内容key
  57. * @return mixed|null
  58. */
  59. public function getConfig($key = null)
  60. {
  61. if(!$key) {
  62. return \Qii\Autoloader\Factory::getInstance('\Qii\Config\Arrays')
  63. ->get('Application');
  64. }
  65. return \Qii\Autoloader\Factory::getInstance('\Qii\Config\Arrays')
  66. ->get('Application['.$key.']');
  67. }
  68. public function setRoute($route = [])
  69. {
  70. Application::$_config['route'] = $route;
  71. }
  72. public function run()
  73. {
  74. print_r($this->getConfig());
  75. }
  76. public static function _i()
  77. {
  78. }
  79. /**
  80. * 抛出异常
  81. *
  82. * @return mixed
  83. */
  84. public static function _e()
  85. {
  86. return call_user_func_array(array('\Qii\Exceptions\Errors', 'e'), func_get_args());
  87. }
  88. }