public static function collect() { // collect all engines if (($engines = b::getClassImplements('\\bolt\\render\\engine\\face')) != false) { foreach ($engines as $class) { if ($class->name === 'bolt\\render\\engine\\base') { continue; } $ext = $class->getConstant('EXT'); if (!b::render('hasEngine', $ext)) { b::render('setEngine', $ext, $class); } } } }
public function render() { // render $str = b::render('file', $this->_file, ['context' => $this->_context, 'vars' => $this->_vars]); return $str; }
public function run() { // loop through and add any engines not already foreach ($this->_engines as $ext => $ref) { b::render('setEngine', $ext, $ref); } // collect to backfill b::render('engine\\collect'); // add routes from controller classes b::browser('route\\collection\\fromControllers', $this->_routes); // before $this->_runMiddleware('before', [$this->_request]); // no response $resp = false; // loop through our middleware // and see if anyone returns a response // if they do, we switch a controller foreach ($this->_middleware as $mid) { $_resp = $mid['instance']->handle($this->_request, $this->_response); if ($_resp and $_resp instanceof \bolt\browser\response) { $resp = $_resp; break; } } // if no response if (!$resp) { // match our route from the request $match = new browser\route\match($this->_routes, $this->_request->getContext()); // we're going to try and match our request // if not we fall back to error try { $params = $match->matchRequest($this->_request); } catch (ResourceNotFoundException $e) { var_dump('bad'); die; } // bind our params to request::attributes $this->_request->attributes->replace($params); // run middle before we run the controller $this->_runMiddleware('before', [$this->_request]); // we can get started $controller = new $params['_controller']($this->_request, $this->_response); // check if we can plugin to the controller if (property_exists($controller, 'isPlugable') and $controller->isPlugable) { $controller->inherit($this); } // build the controller $resp = $controller->run($this->_request->attributes->all()); } if (!$resp) { $resp = $this->_response; } // run middle before we run the controller $this->_runMiddleware('handle', [$this->_request, $this->_response]); // prepare base on request $resp->prepare($this->_request); // figure out if content is callable if (is_callable($resp->getContent())) { while (is_callable($resp->getContent())) { $resp->setContent(call_user_func($resp->getContent())); } } // and done $resp->send(); }