private function getCallback($route, $query_vars) { unset($query_vars['amp_route']); $req = new Request(); $req->setVars($query_vars); $res = new Response(); if (count($route['middlewares']) > 0) { foreach ($route['middlewares'] as $mid) { if (is_object($mid) && $mid instanceof Closure) { ob_start(); $mid($req, $res, $query_vars); $res->write(ob_get_clean()); } else { if (is_string($mid)) { ob_start(); call_user_func_array($mid, array($req, $res, $query_vars)); $res->write(ob_get_clean()); } } } } ob_start(); $route["callback"]($req, $res, $query_vars); $res->write(ob_get_clean()); Ampersand::getInstance()->setRequest($req); Ampersand::getInstance()->setResponse($res); }
private function getCallback($id, $handler, $query_vars) { $req = new Request(); $req->setVars($query_vars); $res = new Callback($req, $query_vars); $route = $this->getRoute($id); if (count($route['middlewares']) > 0) { foreach ($route['middlewares'] as $mid) { $this->runCallback($mid, $query_vars, $res); } } $this->runCallback($handler, $query_vars, $res); Bootstrap::getInstance()->setRequest($req); Bootstrap::getInstance()->setResponse($res); }