Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function fromString($url)
 {
     if (!is_string($url)) {
         throw new InvalidArgumentException('tubepress_url_impl_puzzle_UrlFactory::fromString() can only accept strings.');
     }
     return new tubepress_url_impl_puzzle_PuzzleBasedUrl(puzzle_Url::fromString($url));
 }
Пример #2
0
 public function __construct(puzzle_message_RequestInterface $delegate)
 {
     $this->_delegate = $delegate;
     $stringUrl = $this->_delegate->getUrl();
     $puzzleUrl = puzzle_Url::fromString($stringUrl);
     $this->_url = new tubepress_url_impl_puzzle_PuzzleBasedUrl($puzzleUrl);
     parent::__construct($this->_delegate);
 }
Пример #3
0
 public function testStripsFragmentFromHost()
 {
     puzzle_test_Server::flush();
     puzzle_test_Server::enqueue("HTTP/1.1 200 OK\r\n\r\nContent-Length: 0\r\n\r\n");
     // This will fail if the removal of the #fragment is not performed
     $url = puzzle_Url::fromString(puzzle_test_Server::$url)->setPath(null)->setFragment('foo');
     $client = new puzzle_Client();
     $client->get($url);
 }
Пример #4
0
 public function __construct(puzzle_message_ResponseInterface $delegate)
 {
     $this->_delegate = $delegate;
     $urlString = $this->_delegate->getEffectiveUrl();
     if ($urlString !== null) {
         $puzzleUrl = puzzle_Url::fromString($urlString);
         $this->_effectiveUrl = new tubepress_url_impl_puzzle_PuzzleBasedUrl($puzzleUrl);
     }
     parent::__construct($this->_delegate);
 }
Пример #5
0
 /**
  * Create a request or response object from an HTTP message string
  *
  * @param string $message Message to parse
  *
  * @return puzzle_message_RequestInterface|puzzle_message_ResponseInterface
  * @throws InvalidArgumentException if unable to parse a message
  */
 public function fromMessage($message)
 {
     static $parser;
     if (!$parser) {
         $parser = new puzzle_message_MessageParser();
     }
     // Parse a response
     if (strtoupper(substr($message, 0, 4)) == 'HTTP') {
         $data = $parser->parseResponse($message);
         return $this->createResponse($data['code'], $data['headers'], $data['body'] === '' ? null : $data['body'], $data);
     }
     // Parse a request
     if (!($data = $parser->parseRequest($message))) {
         throw new InvalidArgumentException('Unable to parse request');
     }
     return $this->createRequest($data['method'], puzzle_Url::buildUrl($data['request_url']), array('headers' => $data['headers'], 'body' => $data['body'] === '' ? null : $data['body'], 'config' => array('protocol_version' => $data['protocol_version'])));
 }
Пример #6
0
 /**
  * Set the appropriate URL on the request based on the location header
  *
  * @param puzzle_message_RequestInterface  $redirectRequest
  * @param puzzle_message_ResponseInterface $response
  */
 private function setRedirectUrl(puzzle_message_RequestInterface $redirectRequest, puzzle_message_ResponseInterface $response)
 {
     $location = $response->getHeader('Location');
     $location = puzzle_Url::fromString($location);
     // Combine location with the original URL if it is not absolute.
     if (!$location->isAbsolute()) {
         $originalUrl = puzzle_Url::fromString($redirectRequest->getUrl());
         // Remove query string parameters and just take what is present on
         // the redirect Location header
         $originalUrl->getQuery()->clear();
         $location = $originalUrl->combine($location);
     }
     $redirectRequest->setUrl($location);
 }
Пример #7
0
 private function configureBaseUrl(&$config)
 {
     if (!isset($config['base_url'])) {
         $this->baseUrl = new puzzle_Url('', '');
     } elseif (is_array($config['base_url'])) {
         $this->baseUrl = puzzle_Url::fromString(puzzle_uri_template($config['base_url'][0], $config['base_url'][1]));
         $config['base_url'] = (string) $this->baseUrl;
     } else {
         $this->baseUrl = puzzle_Url::fromString($config['base_url']);
     }
 }
Пример #8
0
 /**
  * {@inheritdoc}
  */
 public function getClone()
 {
     return new self(puzzle_Url::fromString($this->toString()));
 }
Пример #9
0
 public function testConvertsSpecialCharsInPathWhenCastingToString()
 {
     $url = puzzle_Url::fromString('http://foo.com/baz bar?a=b');
     $url->addPath('?');
     $this->assertEquals('http://foo.com/baz%20bar/%3F?a=b', (string) $url);
 }
Пример #10
0
 public function setUrl($url)
 {
     $this->url = $url instanceof puzzle_Url ? $url : puzzle_Url::fromString($url);
     $this->updateHostHeaderFromUrl();
     return $this;
 }
Пример #11
0
 public function testAuthority()
 {
     $url = new tubepress_url_impl_puzzle_PuzzleBasedUrl(puzzle_Url::fromString('http://*****:*****@foo.com:344/baz/bar?a=b'));
     $this->assertEquals('eric:pass@foo.com:344', $url->getAuthority());
 }