getHost() public method

public getHost ( )
Beispiel #1
0
 /**
  * Forward the request to the target url and return the response.
  *
  * @param  string $target
  * @throws UnexpectedValueException
  * @return Response
  */
 public function to($target)
 {
     if (is_null($this->request)) {
         throw new UnexpectedValueException('Missing request instance.');
     }
     $target = new Uri($target);
     // Overwrite target scheme and host.
     $uri = $this->request->getUri()->withScheme($target->getScheme())->withHost($target->getHost());
     // Check for custom port.
     if ($port = $target->getPort()) {
         $uri = $uri->withPort($port);
     }
     // Check for subdirectory.
     if ($path = $target->getPath()) {
         $uri = $uri->withPath(rtrim($path, '/') . '/' . ltrim($uri->getPath(), '/'));
     }
     $request = $this->request->withUri($uri);
     $stack = $this->filters;
     $stack[] = function (RequestInterface $request, ResponseInterface $response, callable $next) {
         $response = $this->adapter->send($request);
         return $next($request, $response);
     };
     $relay = (new RelayBuilder())->newInstance($stack);
     return $relay($request, new Response());
 }
 public function __invoke($route, $console)
 {
     $appId = $route->getMatchedParam('appId');
     $site = $route->getMatchedParam('site');
     $uri = new Uri(trim($site, '/') . '/');
     $port = $uri->getPort();
     if (!$port) {
         $port = $uri->getScheme() == 'https' ? 443 : 80;
     }
     $rules = file_get_contents($this->dist);
     $rules = str_replace('%SCHEME%', $uri->getScheme(), $rules);
     $rules = str_replace('%HOST%', $uri->getHost(), $rules);
     $rules = str_replace('%PORT%', $port, $rules);
     $rules = str_replace('%APPID%', $appId, $rules);
     file_put_contents($this->xml, $rules);
     return 0;
 }