webman
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /**
  3. * This file is part of webman.
  4. *
  5. * Licensed under The MIT License
  6. * For full copyright and license information, please see the MIT-LICENSE.txt
  7. * Redistributions of files must retain the above copyright notice.
  8. *
  9. * @author walkor<walkor@workerman.net>
  10. * @copyright walkor<walkor@workerman.net>
  11. * @link http://www.workerman.net/
  12. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  13. */
  14. use Dotenv\Dotenv;
  15. use support\Log;
  16. use Webman\Bootstrap;
  17. use Webman\Config;
  18. use Webman\Route;
  19. use Webman\Middleware;
  20. use Webman\Util;
  21. $worker = $worker ?? null;
  22. if ($timezone = config('app.default_timezone')) {
  23. date_default_timezone_set($timezone);
  24. }
  25. set_error_handler(function ($level, $message, $file = '', $line = 0) {
  26. if (error_reporting() & $level) {
  27. throw new ErrorException($message, 0, $level, $file, $line);
  28. }
  29. });
  30. if ($worker) {
  31. register_shutdown_function(function ($start_time) {
  32. if (time() - $start_time <= 1) {
  33. sleep(1);
  34. }
  35. }, time());
  36. }
  37. if (class_exists('Dotenv\Dotenv') && file_exists(base_path() . '/.env')) {
  38. if (method_exists('Dotenv\Dotenv', 'createUnsafeImmutable')) {
  39. Dotenv::createUnsafeImmutable(base_path())->load();
  40. } else {
  41. Dotenv::createMutable(base_path())->load();
  42. }
  43. }
  44. Support\App::loadAllConfig(['route']);
  45. foreach (config('autoload.files', []) as $file) {
  46. include_once $file;
  47. }
  48. foreach (config('plugin', []) as $firm => $projects) {
  49. foreach ($projects as $name => $project) {
  50. if (!is_array($project)) {
  51. continue;
  52. }
  53. foreach ($project['autoload']['files'] ?? [] as $file) {
  54. include_once $file;
  55. }
  56. }
  57. foreach ($projects['autoload']['files'] ?? [] as $file) {
  58. include_once $file;
  59. }
  60. }
  61. Middleware::load(config('middleware', []), '');
  62. foreach (config('plugin', []) as $firm => $projects) {
  63. foreach ($projects as $name => $project) {
  64. if (!is_array($project) || $name === 'static') {
  65. continue;
  66. }
  67. Middleware::load($project['middleware'] ?? [], '');
  68. }
  69. Middleware::load($projects['middleware'] ?? [], $firm);
  70. if ($static_middlewares = config("plugin.$firm.static.middleware")) {
  71. Middleware::load(['__static__' => $static_middlewares], $firm);
  72. }
  73. }
  74. Middleware::load(['__static__' => config('static.middleware', [])], '');
  75. foreach (config('bootstrap', []) as $class_name) {
  76. if (!class_exists($class_name)) {
  77. $log = "Warning: Class $class_name setting in config/bootstrap.php not found\r\n";
  78. echo $log;
  79. Log::error($log);
  80. continue;
  81. }
  82. /** @var Bootstrap $class_name */
  83. $class_name::start($worker);
  84. }
  85. foreach (config('plugin', []) as $firm => $projects) {
  86. foreach ($projects as $name => $project) {
  87. if (!is_array($project)) {
  88. continue;
  89. }
  90. foreach ($project['bootstrap'] ?? [] as $class_name) {
  91. if (!class_exists($class_name)) {
  92. $log = "Warning: Class $class_name setting in config/plugin/$firm/$name/bootstrap.php not found\r\n";
  93. echo $log;
  94. Log::error($log);
  95. continue;
  96. }
  97. /** @var Bootstrap $class_name */
  98. $class_name::start($worker);
  99. }
  100. }
  101. foreach ($projects['bootstrap'] ?? [] as $class_name) {
  102. if (!class_exists($class_name)) {
  103. $log = "Warning: Class $class_name setting in plugin/$firm/config/bootstrap.php not found\r\n";
  104. echo $log;
  105. Log::error($log);
  106. continue;
  107. }
  108. /** @var Bootstrap $class_name */
  109. $class_name::start($worker);
  110. }
  111. }
  112. $directory = base_path() . '/plugin';
  113. $paths = [config_path()];
  114. foreach (Util::scanDir($directory) as $path) {
  115. if (is_dir($path = "$path/config")) {
  116. $paths[] = $path;
  117. }
  118. }
  119. Route::load($paths);