public function testPostJson() { $r = new Request(['url' => 'api/tasks/12.json', 'filter' => 'all'], ['HTTP_ACCEPT' => 'application/json;q=0.8', 'REQUEST_URI' => '/api/tasks/12.json?filter=all', 'REQUEST_METHOD' => 'POST'], ['url' => 'api/tasks/12.json', 'filter' => 'all'], ['title' => 'New Title']); $this->assertTrue($r instanceof Request); $this->assertEquals(Request::POST, $r->method()); $this->assertEquals('api/tasks/12.json', $r->url()); $this->assertEquals('json', $r->type()); $this->assertEquals('all', $r->param('filter')); $route = $r->route(); $this->assertTrue($route instanceof Route); $result = $r->response(); $this->assertTrue($result instanceof Response); $this->assertEquals("New Title", $r->param('title')); $expected = ['filter' => 'all']; $result = $r->query(); $this->assertEquals($expected, $result); }
/** * Page constructor. * * Analyze the request url to convert to a view template * * @param Request $request * @param array $config */ public function __construct(Request $request, array $config = []) { $this->_request = $request; $this->_config = $config; $this->_type = $request->type(); $this->_url = $request->route()->url; // @TODO find a different way to do this $parts = \explode('/', $this->_url); $last = \array_slice($parts, -1, 1, true); unset($parts[key($last)]); $this->_path = $parts; $this->_view = current($last); $period = strrpos($this->_view, '.'); if ($period) { $type = substr($this->_view, $period + 1); if (in_array($type, $this->_validTypes)) { $this->_type = $type; $this->_view = substr($this->_view, 0, $period); } } }
if (IS_INSTALLED) { Kohana::$environment = Kohana::PRODUCTION; // Turn off notices and strict errors error_reporting(E_ALL ^ E_NOTICE ^ E_STRICT); } } /** * Set the default language */ I18n::lang('en_US'); if (isset($_SERVER['SERVER_PROTOCOL'])) { // Replace the default protocol. HTTP::$protocol = $_SERVER['SERVER_PROTOCOL']; } if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') { Request::$type = 'https'; } if (isset($_SERVER['HTTP_HOST'])) { Request::$host = str_replace('www.', '', $_SERVER['HTTP_HOST']); } /** * InitializeCore, setting the default options. * * The following options are available: * * - string charset internal character set used for input and output utf-8 * - string cache_dir set the internal cache directory APPPATH/cache * - boolean errors enable or disable error handling TRUE * - boolean profile enable or disable internal profiling TRUE * - boolean caching enable or disable internal caching FALSE */