/** * Execute method * * @param array $routingInfo * @param $controllerName * @param $controllerPath */ public function execute($routingInfo, $controllerName, $controllerPath) { $reflect = new ReflectionClass(ucfirst($controllerName) . 'Controller'); $controllerExemplar = $reflect->newInstance($routingInfo); if (!method_exists($controllerExemplar, $routingInfo['function'])) { crash("Controller '{$controllerName}' does not contained method '{$routingInfo['function']}' controller. Path: {$controllerPath}"); } foreach ($this as $varName => $value) { $this->{$varName} = ${$varName}; } $this->checkNoViewAndIsAjax($controllerExemplar); /** * If established isAjax */ if (controllerManager::$isAjax === true) { if (!isset($_SERVER['HTTP_X_REQUESTED_WITH']) || empty($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower((string) $_SERVER['HTTP_X_REQUESTED_WITH']) !== 'xmlhttprequest' || strtoupper($_SERVER['REQUEST_METHOD']) !== 'POST') { if (Config::$debug === true) { crash('This page may be rendered only within Ajax'); } self::generate404Error(); } Config::$ajaxMode = true; header('Content-Type: application/json'); } else { header('Content-Type: text/html; charset=utf-8'); } if (method_exists($controllerExemplar, 'preController')) { $controllerExemplar->preController($routingInfo); } /** * Begin gradually execute and response */ call_user_func(array($controllerExemplar, $routingInfo['function'])); if (controllerManager::$noView === true || controllerManager::$isAjax === true) { exit; } $this->workingWithView(); }