public function __construct(array $userSettings = [], array $modules = []) { $this->request = Request::createFromGlobals(); $this->locator = Locator::create(); $this->locator->set('settings', $userSettings + self::defaultSettings()); $this->settings = $this->locator->get('settings'); $this->modules = ['Slash\\Module\\AppModule' => new AppModule(), 'Slash\\Module\\TwigModule' => new TwigModule($this->settings['template.path'])] + $modules; $this->runConfiguration(); $this->eventDispatcher = $this->locator->get('Slash\\Event\\Dispatcher\\Impl\\EventDispatcher'); $this->router = $this->locator->get('Slash\\Router'); $this->dispatcher = $this->locator->get('Slash\\ClosureDispatcher'); }
public function resolve(Request $request) { $requestURI = $request->getUri(); $method = $request->getMethod(); $this->matchesRoutes = []; /** @var $route Route */ foreach ($this->routes as $route) { if ($route->matches($requestURI, $method)) { $this->matchesRoutes[] = $route; } } if ($this->matchesRoutes != null) { $this->currentRoute = $this->matchesRoutes[0]; } if ($this->currentRoute == null) { throw new \Exception("Page not found!", Response::NOT_FOUND); } return function () { return call_user_func_array($this->currentRoute->getAction(), $this->currentRoute->getRequirements()); }; }