public function render() { if (Profiler::getState()) { $templatingProfiler = TemplatingProfiler::getInstance(); $templatingProfiler->setRenderingInformation(self::ENGINE, $this->twig->getLoader()->getPaths()[0], $this->template, $this->variables, $this->twig->getCache() ? true : false, $this->twig->getCache(), $this->twig->getCacheFilename($this->template) ? true : false); } return $this->twig->render($this->template, $this->variables); }
public function send() { $this->sendHeaders(); $this->sendContent(); if (Profiler::getState()) { echo Profiler::getInstance()->getProfilerHTMLPanel(); } }
public function render() { $this->smarty->assign($this->variables); $template = $this->smarty->fetch($this->template); if (Profiler::getState()) { $templatingProfiler = TemplatingProfiler::getInstance(); $templatingProfiler->setRenderingInformation(self::ENGINE, $this->smarty->getTemplateDir()[0], $this->template, $this->variables, $this->smarty->caching == Smarty::CACHING_OFF ? false : true, $this->smarty->getCacheDir(), $this->smarty->isCached($this->template)); } return $template; }
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; }
public function executeStatement() { $this->currentQuery = $this->pdo->prepare($this->currentStatement); foreach ($this->currentParams as $param => $info) { $this->currentQuery->bindParam($param, $info['value'], $info['type']); } $initTime = microtime(); $result = $this->currentQuery->execute(); $endTime = microtime(); if (Profiler::getState()) { /** @var PDORepositoryProfiler $profiler */ $profiler = PDORepositoryProfiler::getInstance(); $execTime = $this->calcQueryExecutionDuration($initTime, $endTime); $profiler->addTrace($this->currentStatement, $this->currentParams, $result, $this->getErrorInfo(), $execTime); } return $result; }
public function __invoke(Request $request) { $initTime = microtime(true); $fileParser = FileParserFactory::getParser(YAMLParser::FILE_EXTENSION); $servicesContainer = new ServicesContainer($fileParser); $this->container = $servicesContainer; if (Profiler::getState()) { Profiler::getInstance()->setContainer($this->container); } $routingFile = $this->configurationsDirectoryPath . '/routing.' . $this->generalConfigurations['routingFileExtension']; $routing = $this->container->getService('routing'); /** @var RouteControllerInformation $routeControllerInformation */ $routeControllerInformation = $routing->parseRoute($request, $routingFile); $controllerClassName = $routeControllerInformation->getClassName(); $controllerCallableMethod = $routeControllerInformation->getCallableMethod(); $controller = new $controllerClassName(); if ($this->controllerIsChildOfNightController($controller)) { /** @var NightController $controller */ $controller->setServicesContainer($servicesContainer); } /** @var Response $response */ if ($this->controllerNeedsRequest($controllerClassName, $controllerCallableMethod)) { $response = $controller->{$controllerCallableMethod}($request); } else { $response = $controller->{$controllerCallableMethod}(); } if (is_null($response)) { InvalidResponse::throwDefault(); } $endTime = microtime(true); if (Profiler::getState()) { $executionTime = $this->calcExecutionDuration($initTime, $endTime); Profiler::getInstance()->setResponseStatus($response->getStatus()); Profiler::getInstance()->setExecutionDuration($executionTime); } return $response; }
<?php require_once __DIR__ . '/../vendor/autoload.php'; use Night\Component\Bootstrap\Bootstrap; use Night\Component\Profiling\Profiler; use Night\Component\Request\Request; $bootstrap = new Bootstrap(); $request = Request::newFromGlobals(); Profiler::enable(); /**@var $response \Night\Component\Response\Response */ $response = $bootstrap($request); $response->send();