|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Leantime\Core; |
| 4 | + |
| 5 | +use Illuminate\Container\Container; |
| 6 | +use Illuminate\Filesystem\Filesystem; |
| 7 | +use Illuminate\Foundation\Http\Kernel; |
| 8 | +use Illuminate\Foundation\Mix; |
| 9 | +use Illuminate\Foundation\PackageManifest; |
| 10 | +use Illuminate\Foundation\ProviderRepository; |
| 11 | +use Illuminate\Log\LogServiceProvider; |
| 12 | +use Illuminate\Routing\Router; |
| 13 | +use Illuminate\Routing\RoutingServiceProvider; |
| 14 | +use Illuminate\Support\Collection; |
| 15 | +use Illuminate\Support\Str; |
| 16 | +use Leantime\Core\Configuration\Environment; |
| 17 | +use Leantime\Core\Console\ConsoleKernel; |
| 18 | +use Leantime\Core\Events\DispatchesEvents; |
| 19 | +use Leantime\Core\Http\ApiRequest; |
| 20 | +use Leantime\Core\Http\HttpKernel; |
| 21 | +use Leantime\Core\Http\IncomingRequest; |
| 22 | +use Leantime\Core\Providers\Events; |
| 23 | +use Leantime\Core\Providers\Logging; |
| 24 | + |
| 25 | + |
| 26 | +/** |
| 27 | + * Class Application |
| 28 | + * |
| 29 | + * Represents an application. |
| 30 | + */ |
| 31 | +class Application extends \Illuminate\Foundation\Application |
| 32 | +{ |
| 33 | + use DispatchesEvents; |
| 34 | + |
| 35 | + /** |
| 36 | + * Constructor for the class. |
| 37 | + * |
| 38 | + * @param string $basePath The base path for the application. |
| 39 | + * @return void |
| 40 | + */ |
| 41 | + public function __construct($basePath = null) |
| 42 | + { |
| 43 | + |
| 44 | + $this->publicPath = 'public/'; |
| 45 | + $this->namespace = 'Leantime\\'; |
| 46 | + |
| 47 | + if ($basePath) { |
| 48 | + $this->setBasePath($basePath); |
| 49 | + } |
| 50 | + |
| 51 | + $this->appPath = $basePath."/app/Core"; |
| 52 | + |
| 53 | + //Larevel stores cache in bootstrap folder |
| 54 | + //Cache files are in root in Leantime not in bootstrap |
| 55 | + //Env vars are not available in config |
| 56 | + |
| 57 | + //putenv('APP_EVENTS_CACHE=cache/events.php'); |
| 58 | + //putenv('APP_CONFIG_CACHE=cache/config.php'); |
| 59 | + //putenv('APP_ROUTES_CACHE=cache/routes.php'); |
| 60 | + //putenv('APP_SERVICES_CACHE=cache/services.php'); |
| 61 | + //putenv('APP_PACKAGES_CACHE=cache/packages.php'); |
| 62 | + |
| 63 | + //Our folder structure is different and we shall not bow to the bourgeoisie |
| 64 | + $this->useAppPath($this->basePath.'/app'); |
| 65 | + $this->useConfigPath($this->basePath.'/config'); |
| 66 | + $this->useEnvironmentPath($this->basePath.'/config'); |
| 67 | + $this->useBootstrapPath($this->basePath.'/bootstrap'); |
| 68 | + $this->usePublicPath($this->basePath.'/public'); |
| 69 | + $this->useStoragePath($this->basePath.'/storage'); |
| 70 | + $this->useLangPath($this->basePath.'/app/Language'); |
| 71 | + |
| 72 | + $this->registerBaseBindings(); |
| 73 | + |
| 74 | + //Loading some config vars so we can run events |
| 75 | + //$this->register(new \Leantime\Core\Providers\Environment($this)); |
| 76 | + |
| 77 | + $this->registerBaseServiceProviders(); |
| 78 | + //$this->registerCoreContainerAliases(); |
| 79 | + |
| 80 | + //Overriding some of the aliases |
| 81 | + $this->registerLeantimeAliases(); |
| 82 | + |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * Register the base service providers. |
| 87 | + * |
| 88 | + * This method is used to register the base service providers required for the application. |
| 89 | + * |
| 90 | + * @return void |
| 91 | + */ |
| 92 | + protected function registerBaseServiceProviders() |
| 93 | + { |
| 94 | + //Loading some config vars so we can run events |
| 95 | + //$this->register(new \Leantime\Core\Providers\Environment($this)); |
| 96 | + |
| 97 | + $this->register(new \Leantime\Core\Providers\Events($this)); |
| 98 | + $this->register(new LogServiceProvider($this)); |
| 99 | + $this->register(new RoutingServiceProvider($this)); |
| 100 | + |
| 101 | + //Todo: Add event and see if that works here. |
| 102 | + |
| 103 | + } |
| 104 | + |
| 105 | + public function registerLeantimeAliases() |
| 106 | + { |
| 107 | + |
| 108 | + foreach ([ |
| 109 | + 'app' => [self::class, \Illuminate\Foundation\Application::class, \Illuminate\Contracts\Container\Container::class, \Illuminate\Contracts\Foundation\Application::class, \Psr\Container\ContainerInterface::class], |
| 110 | + 'cache' => [\Illuminate\Cache\CacheManager::class, \Illuminate\Contracts\Cache\Factory::class], |
| 111 | + 'cache.store' => [\Illuminate\Cache\Repository::class, \Illuminate\Contracts\Cache\Repository::class, \Psr\SimpleCache\CacheInterface::class], |
| 112 | + 'cache.psr6' => [\Symfony\Component\Cache\Adapter\Psr16Adapter::class, \Symfony\Component\Cache\Adapter\AdapterInterface::class, \Psr\Cache\CacheItemPoolInterface::class], |
| 113 | + 'config' => [Environment::class, \Illuminate\Config\Repository::class, \Illuminate\Contracts\Config\Repository::class], |
| 114 | + 'encrypter' => [\Illuminate\Encryption\Encrypter::class, \Illuminate\Contracts\Encryption\Encrypter::class, \Illuminate\Contracts\Encryption\StringEncrypter::class], |
| 115 | + 'events' => [\Leantime\Core\Events\EventDispatcher::class, \Illuminate\Events\Dispatcher::class, \Illuminate\Contracts\Events\Dispatcher::class], |
| 116 | + 'request' => [IncomingRequest::class, ApiRequest::class, Console\CliRequest::class, \Illuminate\Http\Request::class, \Symfony\Component\HttpFoundation\Request::class], |
| 117 | + 'redis' => [\Illuminate\Redis\RedisManager::class, \Illuminate\Contracts\Redis\Factory::class], |
| 118 | + 'redis.connection' => [\Illuminate\Redis\Connections\Connection::class, \Illuminate\Contracts\Redis\Connection::class], |
| 119 | + 'session' => [\Illuminate\Session\SessionManager::class], |
| 120 | + 'session.store' => [\Illuminate\Session\Store::class, \Illuminate\Contracts\Session\Session::class], |
| 121 | + 'router' => [Router::class, \Illuminate\Contracts\Routing\Registrar::class, \Illuminate\Contracts\Routing\BindingRegistrar::class], |
| 122 | + 'view' => [\Illuminate\View\Factory::class, \Illuminate\Contracts\View\Factory::class], |
| 123 | + ] as $key => $aliases) { |
| 124 | + foreach ($aliases as $alias) { |
| 125 | + $this->alias($key, $alias); |
| 126 | + } |
| 127 | + } |
| 128 | + |
| 129 | + $this->alias(Application::class, \Illuminate\Contracts\Foundation\Application::class); |
| 130 | + |
| 131 | + //$this->alias(DispatchesEvents::class, 'events'); |
| 132 | + //$this->alias(Environment::class, 'config'); |
| 133 | + } |
| 134 | + |
| 135 | + //Boot with Leantime event dispatcher |
| 136 | + |
| 137 | + |
| 138 | + /** |
| 139 | + * Boot the application. |
| 140 | + * |
| 141 | + * @return void |
| 142 | + */ |
| 143 | + public function boot() |
| 144 | + { |
| 145 | + |
| 146 | + //We need to discover events a lot earlier than Laravel wants us to. |
| 147 | + //So we're just doing it. |
| 148 | + \Illuminate\Support\Facades\Event::discoverListeners(); |
| 149 | + |
| 150 | + //Calling the first event |
| 151 | + self::dispatchEvent('beforeBootingServiceProviders'); |
| 152 | + |
| 153 | + parent::boot(); |
| 154 | + |
| 155 | + self::dispatchEvent('afterBootingServiceProviders'); |
| 156 | + |
| 157 | + } |
| 158 | +} |
0 commit comments