di = new Cli(); $this->app = new Console(); $this->loader = new Loader(); $this->initAppEnv(); $this->initAppConfigs(); $this->initAppSettings(); $this->registerLoaders(); $this->registerServices(); $this->registerErrorHandler(); } public function handle() { $this->app->setDI($this->di); $options = getopt('', ['task:', 'action:']); if (!empty($options['task']) && !empty($options['action'])) { $this->app->handle($options); } else { $options = []; foreach ($_SERVER['argv'] as $k => $arg) { if ($k == 1) { $options['task'] = $arg; } elseif ($k == 2) { $options['action'] = $arg; } elseif ($k >= 3) { $options['params'][] = $arg; } } $this->app->handle($options); echo PHP_EOL . PHP_EOL; } } protected function registerLoaders() { $this->loader->registerNamespaces([ 'App' => app_path(), 'Bootstrap' => bootstrap_path(), ]); $this->loader->registerFiles([ vendor_path('autoload.php'), app_path('Library/Helper.php'), ]); $this->loader->register(); } protected function registerServices() { $providers = [ CacheProvider::class, ConfigProvider::class, CryptProvider::class, DatabaseProvider::class, EventsManagerProvider::class, LoggerProvider::class, MetaDataProvider::class, DispatcherProvider::class, ]; foreach ($providers as $provider) { /** * @var AppProvider $service */ $service = new $provider($this->di); $service->register(); } } protected function registerErrorHandler() { return new ConsoleErrorHandler(); } }