function testPostRequest() { $this->useController('blog'); $this->post('add', array('title' => 'A Post', 'body' => 'With a body.')); $this->assertEquals(array('controller' => 'blog', 'action' => 'add', 'title' => 'A Post', 'body' => 'With a body.'), $this->Request->getParams()); $this->assertTrue($this->Request->isPost()); }
/** * @throws RouteDoesNotMatchRequestException */ public function parametrize(AkRequest $Request) { $this->ensureRequestMethod($Request->getMethod()); $params = $this->extractParamsFromUrl($Request->getRequestedUrl()); $this->addDefaults($params); $this->urlDecode($params); return $params; }
function dispatch() { $this->Request = AkRequest::getInstance(); $this->Response =& AkResponse(); $this->Controller =& $this->Request->recognize(); $this->Controller->process($this->Request, $this->Response); }
/** * @return AkRequest */ function createRequest($url, $method = 'get') { $Request = $this->getMock('AkRequest', array('getRequestedUrl', 'getMethod', 'getRelativeUrlRoot')); $Request->expects($this->any())->method('getRequestedUrl')->will($this->returnValue($url)); $Request->expects($this->any())->method('getMethod')->will($this->returnValue($method)); $Request->expects($this->any())->method('getRelativeUrlRoot')->will($this->returnValue('')); AkRequest::$singleton = $Request; return $this->Request = $Request; }
function __construct($Request = null, AkRouter $Router = null) { if (!$Router) { $Router = AkRouter::getInstance(); } if (!$Request) { $Request = AkRequest::getInstance(); } $this->Request = $Request; $this->Router = $Router; $this->persistValuesFromRequest($Request); }
function testInvestigateRequest() { $Request = new AkRequest(); $Request->_request['ak'] = 'blog/show/1'; $Request->_request['q'] = 'wer'; $Router = new AkRouter(); $Router->connect(':controller/:action/:id'); $Request->checkForRoutedRequests($Router); $this->assertEquals(array( 'controller'=>'blog', 'action'=>'show', 'id'=>1, 'q'=>'wer', 'ak'=>'blog/show/1'),$Request->getParameters()); # we don't need the 'ak'-key, do we? #var_dump($Request->getRequestUri()); # http://localhost/ #var_dump($Request->getHost()); # localhost #var_dump($Request->getHostWithPort()); # localhost #var_dump($Request->getMethod()); # env->request_method #var_dump($Request->getLocaleFromUrl()); # #var_dump($Request->getPath()); # env->request_uri #var_dump($Request->getPathParameters());# possibly orhpaned }
public function dispatchAppServer($context) { $_ENV = $_SERVER = $context['env']; @parse_str($_ENV['QUERY_STRING'], $_GET); $_GET['ak'] = $_ENV['PATH_INFO']; Ak::unsetStaticVar('AkRequestSingleton'); Ak::unsetStaticVar('AkRouterSingleton'); Ak::unsetStaticVar('AkUrlWriterSingleton'); AkConfig::setOption('Request.remote_ip', '127.0.0.1'); try { $time_start = microtime(true); AK_ENABLE_PROFILER && AkDebug::profile(__CLASS__ . '::' . __FUNCTION__ . '() call'); $this->Request = AkRequest::getInstance(); $this->Response = new AkResponse(); $path = ltrim(str_replace('..', '.', $context['env']['REQUEST_URI']), '/. '); if (empty($path) && file_exists(AK_PUBLIC_DIR . DS . 'index.html')) { $Controller = new AkActionController(); $Controller->Response = $this->Response; $Controller->renderText(file_get_contents(AK_PUBLIC_DIR . DS . 'index.html')); return $Controller->Response; } elseif (!empty($path) && file_exists(AK_PUBLIC_DIR . DS . $path)) { $Controller = new AkActionController(); $Controller->Response = $this->Response; $Controller->sendFile(AK_PUBLIC_DIR . DS . $path, array('stream' => false)); return $Controller->Response; } else { if ($this->Controller = $this->Request->recognize()) { $this->Controller->ak_time_start = $time_start; AK_ENABLE_PROFILER && AkDebug::profile('Request::recognize() completed'); $this->Controller->process($this->Request, $this->Response); } return $this->Response; } } catch (Exception $e) { if (isset($this->Controller) && method_exists($this->Controller, 'render_error')) { $this->Controller->render_error($e); } else { $ExceptionDispatcher = new AkExceptionDispatcher(); $ExceptionDispatcher->renderException($e); } } }
function init(&$ParentController) { $this->__ParentController =& $ParentController; $this->__ParentController->_ssl_requirement ? $this->__ParentController->beforeFilter('_ensureProperProtocol') : false; if ($this->__ParentController->_autoIncludePaginator) { require_once AK_LIB_DIR . DS . 'AkActionController' . DS . 'AkPaginator.php'; } if (AK_WEB_REQUEST_CONNECT_TO_DATABASE_ON_INSTANTIATE) { $this->__ParentController->__connectToDatabase(); } if (AK_WEB_REQUEST_START_SESSION_ON_INSTANTIATE) { $this->__ParentController->__startSession(); } require_once AK_LIB_DIR . DS . 'AkRequest.php'; $this->__ParentController->Request = AkRequest::getInstance(); if (AK_WEB_REQUEST_ENABLE_INTERNATIONALIZATION_SUPPORT_ON_INSTANTIATE && AK_AVAILABLE_LOCALES != 'en') { $this->__ParentController->__enableInternationalizationSupport(); } $this->__ParentController->__mapRoutes(); }
public function __construct() { if (!(AK_DEV_MODE && AkRequest::isLocal())) { throw new ForbiddenActionException('You can only access the Akelos Panel from localhost and when running development environment.'); } }
public function test_should_normalize_simple_level_as_array_file_uploads() { $Request = new AkRequest(); $_FILES = array('image' => array('name' => array(0 => 'mod_rewrite_cheat_sheet.pdf', 1 => 'microformats_cheat_sheet.pdf', 2 => ''), 'type' => array(0 => 'application/pdf', 1 => 'application/pdf', 2 => ''), 'tmp_name' => array(0 => '/tmp/phpXpfUKA', 1 => '/tmp/phpkB6MnX', 2 => ''), 'error' => array(0 => 0, 1 => 0, 2 => 4), 'size' => array(0 => 332133, 1 => 427735, 2 => 0))); $normalized = array('image' => array(0 => array('name' => 'mod_rewrite_cheat_sheet.pdf', 'tmp_name' => '/tmp/phpXpfUKA', 'size' => 332133, 'type' => 'application/pdf', 'error' => 0), 1 => array('name' => 'microformats_cheat_sheet.pdf', 'tmp_name' => '/tmp/phpkB6MnX', 'size' => 427735, 'type' => 'application/pdf', 'error' => 0))); $this->assertEqual($Request->_getNormalizedFilesArray(), $normalized); }
function test_for_getSubDomains() { $Request = new AkRequest(); $env_backup = $Request->env; $Request->_host = 'www.dev.akelos.com'; $this->assertEqual($Request->getSubdomains(), array('www', 'dev')); $this->assertEqual($Request->getSubdomains(2), array('www')); $Request->env = $env_backup; }
/** * @return AkRequest */ static function getInstance() { if (!self::$singleton) { self::$singleton = new AkRequest(); } return self::$singleton; }
public function __construct() { if (!AkRequest::isLocal()) { $this->beforeFilter(array('authenticate' => array('except' => array('index')))); } }
function testGetFormatReturnsContentTypeOnPutRequests() { $this->Request->env['REQUEST_METHOD'] = 'put'; $this->Request->env['CONTENT_TYPE'] = 'text/xml;charset=utf-8'; $this->assertEquals('xml', $this->Request->getFormat()); }
public function persistValuesFromRequest(AkRequest $Request) { $this->values_from_request = array('relative_url_root' => $Request->getRelativeUrlRoot(), 'protocol' => $Request->getProtocol(), 'host' => $Request->getHostWithPort()); $this->parameters_from_actual_request = $Request->getParametersFromRequestedUrl(); }