/** * Runs the application */ public function run() { $this->_hookManager->runBeforeSystem(); $urlArray = explode('/', $this->_url); //Deletes last element if empty $lastElement = end($urlArray); if ($lastElement == '') { array_pop($urlArray); } reset($urlArray); // If present take the first element as the controller $tmpController = isset($urlArray[0]) ? array_shift($urlArray) : 'index'; $action = null; //Prepare the GET params in order to pass them to the Controller $myGet = $_GET; if (isset($myGet['url'])) { unset($myGet['url']); } if ($this->applyStaticRouting($tmpController)) { $this->_hookManager->runBefore(); // Runs before controller hooks include ROOT . DS . $tmpController; $this->_hookManager->runAfter(); // Runs after controller hooks } elseif ($this->applyRouting($tmpController, $action, $urlArray)) { $action === null ? $action = 'index' : $action; $tmpController = '\\pff\\controllers\\' . $tmpController; $controller = new $tmpController($tmpController, $this, $action, array_merge($urlArray, $myGet)); } elseif (file_exists(ROOT . DS . 'app' . DS . 'controllers' . DS . ucfirst($tmpController) . '_Controller.php')) { $action = isset($urlArray[0]) ? array_shift($urlArray) : 'index'; $controllerClassName = '\\pff\\controllers\\' . ucfirst($tmpController) . '_Controller'; $controller = new $controllerClassName($tmpController, $this, $action, array_merge($urlArray, $myGet)); } else { throw new RoutingException('Cannot find a valid controller.', 404); } if (isset($controller)) { $this->_action = $action; $this->_moduleManager->setController($controller); // We have a controller, let the modules know about it ob_start(); $this->_hookManager->runBefore(); // Runs before controller hooks if ((int) method_exists($controller, $this->_action)) { call_user_func_array(array($controller, "beforeAction"), $urlArray); call_user_func(array($controller, "beforeFilter")); call_user_func_array(array($controller, $this->_action), $urlArray); call_user_func(array($controller, "afterFilter")); call_user_func_array(array($controller, "afterAction"), $urlArray); $this->_hookManager->runAfter(); // Runs after controller hooks ob_end_flush(); } else { throw new RoutingException('Not a valid action: ' . $action, 404); } } }
public function testFailsToRegisterAnEmptyProvider() { $this->setExpectedException('\\pff\\Exception\\HookException'); $stub = $this->getMock('\\pff\\Iface\\IHookProvider'); $this->object->registerHook($stub, 'name'); }