protected function fallback($name, $parms, $args) { $name = trim($name, '/'); $this->views_paths[] = ''; $template = $this->search_fallback_template($name); if ($template) { $args = array('env' => WS::env(), 'request' => WS::env()->request, 'args' => $parms, 'args_array' => $args, 'insertion_name' => $name); Events::call("cms.insertions.template.{$name}", $template, $args); if (isset($this->args['layout'])) { return $this->args['layout']->root->partial($template, $args); } return Templates::HTML($template)->with($args)->render(); } return null; }
/** * @param WS_Environment $env * * @return Net_HTTP_Response */ public function run(WS_Environment $env) { //if ($this->disabled) return $this->application->run($env); $error = null; try { $body = $this->application->run($env); $response = Net_HTTP::merge_response($body, $env->response); } catch (Exception $e) { $error = $e; if ($this->disabled) { throw $e; } $response = Net_HTTP::Response(Net_HTTP::INTERNAL_SERVER_ERROR); } if (!$response->body && ($template = $this->find_template_name_for($response->status))) { if (isset($env->not_found->static_file)) { $response->body(IO_FS::File($env->not_found->static_file)); } else { $layout = isset($env->not_found->layout) ? $env->not_found->layout : 'work'; $view = Templates::HTML($template); if ($layout) { $view->within_layout($layout); } $view->root->with(array('env' => $env, 'response' => $response, 'error' => $error)); if ($view->exists()) { $response->body($view); } else { if (IO_FS::exists($static_name = $template . '.html')) { $response->body(IO_FS::File($static_name)); } } } } Events::call('ws.status', $response); return $response; }