public function parseRoute(Request $request, $routingFile) { $initTime = microtime(); $fileContents = $this->fileParser->parseFile($routingFile); $routeParameters = []; $explodedRoute = array_slice(explode('/', $request->getRequestUri()), 1); foreach ($fileContents as $routeEntry) { $routeDefinition = $routeEntry['route']; $explodedDefinition = array_slice(explode('/', $routeDefinition), 1); if (count($explodedRoute) != count($explodedDefinition)) { continue; } if ($explodedRoute[0] != $explodedDefinition[0]) { continue; } $isParam = false; for ($elementIterator = 0; $elementIterator < count($explodedDefinition); $elementIterator++) { if ($this->definitionElementIsParameter($explodedDefinition[$elementIterator]) || $isParam) { $isParam = true; $paramName = str_replace(['{', '}'], '', $explodedDefinition[$elementIterator]); $routeParameters[$paramName] = $explodedRoute[$elementIterator]; } else { if ($explodedDefinition[$elementIterator] != $explodedRoute[$elementIterator]) { break; } } if ($elementIterator == count($explodedDefinition) - 1) { $request->route = new Route($routeDefinition, $routeParameters); $className = $routeEntry['path']['classname']; $callableMethod = $routeEntry['path']['callablemethod']; $routeControllerInformation = new RouteControllerInformation($className, $callableMethod); break 2; } } } if (!isset($routeControllerInformation)) { $notFoundClassName = $fileContents['notfound']['path']['classname']; $notFoundCallableMethod = $fileContents['notfound']['path']['callablemethod']; $routeControllerInformation = new RouteControllerInformation($notFoundClassName, $notFoundCallableMethod); $routeDefinition = 'Default Not Found'; } $endTime = microtime(); if (Profiler::getState()) { $parsingDuration = $this->calcParsingDuration($initTime, $endTime); RoutingProfiler::getInstance()->setInformation($request->getRequestUri(), $routeDefinition, $routeParameters, $parsingDuration); } return $routeControllerInformation; }
<?php require_once __DIR__ . '/../vendor/autoload.php'; use Night\Component\Bootstrap\Bootstrap; use Night\Component\Request\Request; $bootstrap = new Bootstrap(); $request = Request::newFromGlobals(); /**@var $response \Night\Component\Response\Response */ $response = $bootstrap($request); $response->send();