Example #1
0
 /**
  * Tries to detect the base URI of request.
  *
  * @return void
  */
 protected function detectBaseUri()
 {
     if (isset($this->settings['http']['baseUri']) && $this->settings['http']['baseUri'] !== NULL) {
         $this->baseUri = new Uri($this->settings['http']['baseUri']);
     } else {
         $this->baseUri = clone $this->uri;
         $this->baseUri->setQuery(NULL);
         $this->baseUri->setFragment(NULL);
         $this->baseUri->setPath($this->getScriptRequestPath());
     }
 }
Example #2
0
 /**
  * @test
  * @expectedException \InvalidArgumentException
  */
 public function settingInvalidHostThrowsException()
 {
     $uri = new Uri('');
     $uri->setHost('an#invalid.host');
 }
Example #3
0
 /**
  * Creates a new Request object from the given data.
  *
  * @param \TYPO3\FLOW3\Http\Uri $uri The request URI
  * @param string $method Request method, for example "GET"
  * @param array $arguments
  * @param array $files
  * @param array $server
  * @return \TYPO3\FLOW3\Http\Request
  * @throws \InvalidArgumentException
  * @api
  */
 public static function create(Uri $uri, $method = 'GET', array $arguments = array(), array $files = array(), array $server = array())
 {
     if (!in_array($method, array('OPTIONS', 'GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'TRACE', 'CONNECT'))) {
         throw new \InvalidArgumentException(sprintf('Invalid method "%s".', $method), 1326706916);
     }
     $get = $uri->getArguments();
     $post = $arguments;
     $isDefaultPort = $uri->getScheme() === 'https' ? $uri->getPort() === 443 : $uri->getPort() === 80;
     $defaultServerEnvironment = array('HTTP_USER_AGENT' => 'FLOW3/' . FLOW3_VERSION_BRANCH . '.x', 'HTTP_HOST' => $uri->getHost() . ($isDefaultPort !== TRUE ? ':' . $uri->getPort() : ''), 'SERVER_NAME' => $uri->getHost(), 'SERVER_ADDR' => '127.0.0.1', 'SERVER_PORT' => $uri->getPort() ?: 80, 'REMOTE_ADDR' => '127.0.0.1', 'SCRIPT_FILENAME' => FLOW3_PATH_WEB . 'index.php', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'SCRIPT_NAME' => '/index.php', 'PHP_SELF' => '/index.php');
     if ($uri->getScheme() === 'https') {
         $defaultServerEnvironment['HTTPS'] = 'on';
         $defaultServerEnvironment['SERVER_PORT'] = $uri->getPort() ?: 443;
     }
     if (in_array($method, array('POST', 'PUT', 'DELETE'))) {
         $defaultServerEnvironment['HTTP_CONTENT_TYPE'] = 'application/x-www-form-urlencoded';
     }
     $query = $uri->getQuery();
     $fragment = $uri->getFragment();
     $overrideValues = array('REQUEST_URI' => $uri->getPath() . ($query !== '' ? '?' . $query : '') . ($fragment !== '' ? '#' . $fragment : ''), 'REQUEST_METHOD' => $method, 'QUERY_STRING' => $query);
     $server = array_replace($defaultServerEnvironment, $server, $overrideValues);
     return new static($get, $post, $files, $server);
 }