/** * Get Route including 404 check * * @see core/CodeIgniter.php * * @return array [class, method, pararms] */ public function getRoute() { $RTR =& load_class('Router', 'core'); $URI =& load_class('URI', 'core'); $e404 = FALSE; $class = ucfirst($RTR->class); $method = $RTR->method; if (empty($class) or !file_exists(APPPATH . 'controllers/' . $RTR->directory . $class . '.php')) { $e404 = TRUE; } else { require_once APPPATH . 'controllers/' . $RTR->directory . $class . '.php'; if (!class_exists($class, FALSE) or $method[0] === '_' or method_exists('CI_Controller', $method)) { $e404 = TRUE; } elseif (method_exists($class, '_remap')) { $params = array($method, array_slice($URI->rsegments, 2)); $method = '_remap'; } elseif (!in_array(strtolower($method), array_map('strtolower', get_class_methods($class)), TRUE)) { $e404 = TRUE; } } if ($e404) { // If 404, CodeIgniter instance is not created yet. So create it here. // Because we need CI->output->_status $CI =& get_instance(); if ($CI instanceof CIPHPUnitTestNullCodeIgniter) { CIPHPUnitTest::createCodeIgniterInstance(); } show_404($RTR->directory . $class . '/' . $method . ' is not found'); } if ($method !== '_remap') { $params = array_slice($URI->rsegments, 2); } return [$class, $method, $params]; }
/** * Call Controller Method * * @param string $http_method HTTP method * @param array $argv controller, method [, arg1, ...] * @param array|string $request_params POST params/GET params|raw_input_stream */ protected function callControllerMethod($http_method, $argv, $request_params) { $_SERVER['argv'] = array_merge(['index.php'], $argv); $class = ucfirst($argv[0]); $method = $argv[1]; // Remove controller and method array_shift($argv); array_shift($argv); // $request = [ // 'REQUEST_METHOD' => $_SERVER['REQUEST_METHOD'], // 'class' => $class, // 'method' => $method, // 'params' => $argv, // '$_GET' => $_GET, // '$_POST' => $_POST, // ]; // var_dump($request, $_SERVER['argv']); // Reset CodeIgniter instance state reset_instance(); $this->setRawInputStream($request_params); // 404 checking if (!class_exists($class) || !method_exists($class, $method)) { // If 404, CodeIgniter instance is not created yet. So create it here // Because we need CI->output->_status to store info $CI =& get_instance(); if ($CI instanceof CIPHPUnitTestNullCodeIgniter) { CIPHPUnitTest::createCodeIgniterInstance(); } show_404($class . '::' . $method . '() is not found'); } $params = $argv; return $this->createAndCallController($class, $method, $params); }
/** * Reset CodeIgniter instance and assign new CodeIgniter instance as $this->CI */ public function resetInstance() { reset_instance(); CIPHPUnitTest::createCodeIgniterInstance(); $this->CI =& get_instance(); }