public function execute($args) { $arguments = func_get_args(); $callback = $arguments[0]; if (!is_callable($callback)) { Exception::trigger_error('First argument is expected to be a valid callback', E_USER_WARNING); } array_shift($arguments); return call_user_func_array($callback, $arguments); }
/** * Dispatch an HTTP request to a controller/action. * * @param Yaf_Request_Abstract|null $request * @return void|Yaf_Response_Abstract */ public function dispatch(Request_Abstract $request = null) { /** * Instantiate default request object (HTTP version) if none provided */ if ($request == null) { $request = $this->getRequest(); } else { $this->setRequest($request); } if (!$request instanceof Request_Abstract) { throw new Exception\TypeError('Expect a Yaf_Request_Abstract instance'); } if ($request instanceof Request\Http) { $response = new Response\Http(); } elseif ($request instanceof Request\Simple) { $response = new Response\Cli(); } /** * Initialize router */ $router = $this->getRouter(); if (!$request->isRouted()) { /** * Notify plugins of router startup */ foreach ($this->_plugins as $plugin) { $plugin->routerStartup($request, $response); } try { //@todo here seems there is 2 type of routes $router->route($request); } catch (\Exception $e) { if ($this->throwException() == true) { throw $e; } } $this->_fixDefault($request); /** * Notify plugins of router shutdown */ foreach ($this->_plugins as $plugin) { $plugin->routerShutdown($request, $response); } } else { $this->_fixDefault($request); } $view = $this->initView(); /** * Notify plugins of dispatch loop startup */ foreach ($this->_plugins as $plugin) { $plugin->dispatchLoopStartup($request, $response); } $nested = G::iniGet('yaf.forward_limit'); // Begin dispatch try { /** * Route request to controller/action, if a router is provided */ do { /** * Notify plugins of dispatch startup */ foreach ($this->_plugins as $plugin) { $plugin->preDispatch($request, $response); } /** * Dispatch request */ $this->handle($request, $response, $view); $this->_fixDefault($request); /** * Notify plugins of dispatch completion */ foreach ($this->_plugins as $plugin) { $plugin->postDispatch($request, $response); } $nested--; } while (!$request->isDispatched() && $nested > 0); /** * Notify plugins of dispatch loop completion */ foreach ($this->_plugins as $plugin) { $plugin->dispatchLoopShutdown($request, $response); } } catch (\Exception $e) { if ($this->throwException()) { throw $e; } else { Exception::trigger_error($e->getMessage(), E_USER_ERROR); } } if ($nested == 0 && !$request->isDispatched()) { throw new Exception\DispatchFailed('The max dispatch nesting ' . G::iniGet('yaf.forward_limit') . ' was reached'); } if ($this->returnResponse() == false) { $response->response(); } return $response; }
private function resolveDirectory($class) { if ($this->isLocalName($class)) { $directory = $this->_library; } else { $directory = $this->_globalLibrary; } if ($directory == '') { Exception::trigger_error('Yaf_Loader requires Yaf_Application' . '(which set the library_directory) to be initialized first', E_USER_WARNING); } return $directory; }