/** * This is the request entry point, once the Bootstrap has been initialized. * The method initializes router and tries to call the callback assigned to the current url. * Method is call automatically from the Bootstrap class. * * @param string $url Url to route. If not set, the current url is used. * * @throws \Exception * * @return Dispatcher */ public function initializeRouter($url = null) { // current url $currentUrl = is_null($url) ? $this->httpRequest()->getCurrentUrl() : $url; // init the router try { // try matching a custom route $result = $this->router()->match($currentUrl); if ($result) { // custom route matched // based on callback, route the request $callback = $result->getCallback(); // namespace $ns = Bootstrap::getInstance()->getEnvironment()->getApplicationConfig()->get('Namespace', false); // extract callback parts $callbackData = $this->str($callback['Class'])->trimLeft('\\')->trimLeft($ns)->explode('\\')->val(); if ($callbackData[1] == 'Modules' && $callbackData[3] == 'Controllers') { // custom route, but still an MVC application return $this->dispatchMvc($callbackData[2], $callbackData[4], $callback['Method'], $result->getParams()); } else { // custom route and custom callback (non MVC) return $this->dispatchCustom($callback['Class'], $callback['Method'], $result->getParams()); } } else { // fallback to the mvc router return $this->mvcRouter($this->httpRequest()->getCurrentUrl(true)->getPath()); } } catch (\Exception $e) { throw $e; } throw new BootstrapException('No router matched the request.'); }
public function testGetEnvironment() { $env = \Webiny\Component\Bootstrap\Bootstrap::getInstance()->getEnvironment(); $this->assertInstanceOf('\\Webiny\\Component\\Bootstrap\\Environment', $env); }
/** * Create a new Application instance. The method also sets the current configuration and environment inside the * Application instance. * * @return Application * @throws BootstrapException */ private function getApplicationInstance() { // create the app instance $app = new Application(Bootstrap::getInstance()->getEnvironment()); return $app; }