getBundles(); $bundles_instances = []; $this->app_root_dir = realpath(__DIR__ . "/../"); $this->routing_service = new Routing($this); $this->container_service = new Container($this); $this->services_service = new Services($this); $this->providers_service = new Providers($this, new \Configuration\Providers()); // Import configuration $this->container_service->import(new Configuration($this), "configuration"); $this->container_service->import(new Parameters($this), "parameters"); $this->counter = new Counter($this); // Require and instanciate all defined bundles foreach ($bundles as $bundle) { if (file_exists(__DIR__ . "/../src/" . $bundle . "/Bundle.php")) { require_once __DIR__ . "/../src/" . $bundle . "/Bundle.php"; $class_name = str_replace("/", "\\", $bundle) . "\\Bundle"; $bundles_instances[] = new $class_name($this); } else { error_log("No such bundle " . $bundle); } } // Init routing for all bundles foreach ($bundles_instances as $bundle_instance) { $bundle_instance->init(); } } public function getRouting() { return $this->routing_service; } public function getContainer() { return $this->container_service; } public function getServices() { return $this->services_service; } public function getProviders() { return $this->providers_service; } public function getAppRootDir() { return $this->app_root_dir; } public function getCommands() { return $this->commands; } public function getCounter() { return $this->counter; } public function runCli() { if (php_sapi_name() == "cli") { $this->commands = new CommandsManager($this, (new Commands())->commands); ($this->commands)->run(); } } public function run() { try{ SimpleRouter::start(); }catch(\Exception $err){ error_log($err); http_response_code(500); echo '{"error": "'.$err->getMessage().'"}'; } } }