Просмотр файла app/bootstrap.php

Размер файла: 4.11Kb
  1. <?php
  2.  
  3. declare(strict_types = 1);
  4.  
  5. use Illuminate\Cache\CacheManager;
  6. use Illuminate\Cache\MemcachedConnector;
  7. use Illuminate\Config\Repository;
  8. use Illuminate\Container\Container;
  9. use Illuminate\Database\Capsule\Manager as DB;
  10. use Illuminate\Events\Dispatcher;
  11. use Illuminate\Filesystem\Filesystem;
  12. use Illuminate\Log\LogManager;
  13. use Illuminate\Pagination\PaginationServiceProvider;
  14. use Illuminate\Redis\RedisManager;
  15. use Illuminate\Support\Arr;
  16. use Illuminate\Support\Facades\Facade;
  17. use Illuminate\Translation\FileLoader;
  18. use Illuminate\Translation\Translator;
  19. use Illuminate\View\Compilers\BladeCompiler;
  20. use Illuminate\View\Engines\CompilerEngine;
  21. use Illuminate\View\Engines\EngineResolver;
  22. use Illuminate\View\Engines\PhpEngine;
  23. use Illuminate\View\Factory;
  24. use Illuminate\View\FileViewFinder;
  25. use Whoops\Handler\PlainTextHandler;
  26. use Whoops\Handler\PrettyPageHandler;
  27. use Whoops\Run;
  28. use Whoops\Util\Misc;
  29.  
  30. define('STARTTIME', microtime(true));
  31. define('BASEDIR', dirname(__DIR__));
  32. define('SITETIME', time());
  33. const APP = BASEDIR . '/app';
  34. const HOME = BASEDIR . '/public';
  35. const UPLOADS = HOME . '/uploads';
  36. const RESOURCES = BASEDIR . '/resources';
  37. const STORAGE = BASEDIR . '/storage';
  38. const MODULES = BASEDIR . '/modules';
  39. const VERSION = '9.5';
  40.  
  41. require_once BASEDIR . '/vendor/autoload.php';
  42.  
  43. if (config('app.debug')) {
  44. if (class_exists(Run::class)) {
  45. $handler = Misc::isCommandLine() ?
  46. new PlainTextHandler() :
  47. new PrettyPageHandler();
  48.  
  49. $whoops = new Run();
  50. $whoops->prependHandler($handler);
  51. $whoops->pushHandler(static function () {
  52. $_SERVER = Arr::except($_SERVER, array_keys($_ENV));
  53. $_ENV = [];
  54. });
  55. $whoops->register();
  56. } else {
  57. error_reporting(E_ALL);
  58. ini_set('display_errors', '1');
  59. ini_set('display_startup_errors', '1');
  60. }
  61. }
  62.  
  63. date_default_timezone_set(config('app.timezone'));
  64.  
  65. /**
  66. * Setup a new app instance container
  67. */
  68. $app = new Container();
  69.  
  70. $app->singleton('config', static function () {
  71. return new Repository(config());
  72. });
  73.  
  74. $app->singleton('files', static function () {
  75. return new Filesystem();
  76. });
  77.  
  78. $app->singleton('events', static function ($app) {
  79. return new Dispatcher($app);
  80. });
  81.  
  82. $app->singleton('request', static function () {
  83. return request();
  84. });
  85.  
  86. $app->singleton('translator', static function ($app) {
  87. $translator = new Translator(
  88. new FileLoader(
  89. $app['files'],
  90. RESOURCES . '/lang'
  91. ),
  92. setting('language')
  93. );
  94.  
  95. $translator->setFallback(setting('language_fallback'));
  96.  
  97. return $translator;
  98. });
  99.  
  100. $app->singleton('view', static function ($app) {
  101. $resolver = new EngineResolver();
  102.  
  103. $resolver->register('blade', static function () use ($app) {
  104. $blade = new BladeCompiler(
  105. $app['files'],
  106. STORAGE . '/views'
  107. );
  108.  
  109. return new CompilerEngine($blade);
  110. });
  111.  
  112. $resolver->register('php', static function () use ($app) {
  113. return new PhpEngine($app['files']);
  114. });
  115.  
  116. $finder = new FileViewFinder(
  117. $app['files'],
  118. [
  119. HOME . '/themes/' . setting('themes') . '/views',
  120. RESOURCES . '/views',
  121. HOME . '/themes',
  122. ]
  123. );
  124.  
  125. return new Factory($resolver, $finder, $app['events']);
  126. });
  127.  
  128. $app->singleton('log', static function ($app) {
  129. return new LogManager($app);
  130. });
  131.  
  132. if (config('cache.default') === 'redis') {
  133. $app->bind('redis', static function () use ($app) {
  134. return new RedisManager($app, 'phpredis', config('database.redis'));
  135. });
  136. }
  137.  
  138. if (config('cache.default') === 'memcached') {
  139. $app->bind('memcached.connector', static function () {
  140. return new MemcachedConnector();
  141. });
  142. }
  143.  
  144. $cacheManager = new CacheManager($app);
  145. $app->instance('cache', $cacheManager);
  146.  
  147. $pagination = new PaginationServiceProvider($app);
  148. $pagination->register();
  149.  
  150. $db = new DB();
  151. $db->addConnection(config('database.connections.' . config('database.default')));
  152. $db->setAsGlobal();
  153. $db->bootEloquent();
  154. $db::connection()->enableQueryLog();
  155.  
  156. /**
  157. * Set $app as FacadeApplication handler
  158. */
  159. Facade::setFacadeApplication($app);