/** * @param ApplicationInterface * * @return array */ public function run(ApplicationInterface $app) { // Vars class holds view variables // // you can return an array of view variables or // directly call it Vars::set('page.title', 'Objective PHP Project Template'); }
/** * @param ApplicationInterface $app * @return mixed * @throws \ObjectivePHP\Primitives\Exception * @internal param ApplicationInterface $application * */ public function run(ApplicationInterface $app) { $result = parent::run($app); if ($result instanceof Response) { $app->setResponse($result); } else { // set default content type $app->setResponse((new HttpResponse())->withHeader('Content-Type', 'text/html')); Collection::cast($result)->each(function ($value, $var) { Vars::set($var, $value); }); } }
/** * @param $viewName * @param array $context * * @return string * @throws Exception */ public function render($viewPath, $vars = []) { foreach ($vars as $reference => $value) { Vars::set($reference, $value); } if (!file_exists($viewPath)) { throw new Exception(sprintf('View script "%s" does not exist', $viewPath)); } ob_start(); include $viewPath; $output = ob_get_clean(); return $output; }
public function run(ApplicationInterface $app) { $matchedRoute = $app->getRequest()->getMatchedRoute(); $action = Invokable::cast($matchedRoute->getAction()); $app->getServicesFactory()->injectDependencies($action->getCallable()); $app->setParam('runtime.action.middleware', $action); $result = $action->getCallable()($app); if ($result instanceof Response) { $app->setResponse($result); } else { // set default content type $app->setResponse((new HttpResponse())->withHeader('Content-Type', 'text/html')); Collection::cast($result)->each(function ($value, $var) { Vars::set($var, $value); }); } }