/** * Needs to be public because of closure */ public function dispatch($method_name, $method_args) { $request = $this->slim->request(); $response = $this->slim->response(); // Check whether route is using a controller or the current class if (preg_match('/\\A(?:[A-Z]\\w+::[A-Z|a-z|_]\\w+)\\Z/', $method_name)) { $parts = explode('::', $method_name); $object = $this->loadController($parts[0]); $method_name = $parts[1]; } else { $object =& $this; } $response = call_user_func_array(array($object, $method_name . '_' . strtolower($request->getMethod())), $method_args); if (!empty($this->layoutTemplate)) { $response = $this->template->loadTemplate($this->layoutTemplate, array('content' => $response)); } if (!empty($this->pageTemplate)) { $response = $this->template->loadTemplate($this->pageTemplate, array('content' => $response)); } echo $response; }