コード例 #1
0
ファイル: MessageFactory.php プロジェクト: hilmysyarif/sic
 /**
  * Create a request or response object from an HTTP message string
  *
  * @param string $message Message to parse
  *
  * @return RequestInterface|ResponseInterface
  * @throws \InvalidArgumentException if unable to parse a message
  */
 public function fromMessage($message)
 {
     static $parser;
     if (!$parser) {
         $parser = new 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'], Url::buildUrl($data['request_url']), ['headers' => $data['headers'], 'body' => $data['body'] === '' ? null : $data['body'], 'config' => ['protocol_version' => $data['protocol_version']]]);
 }
コード例 #2
0
ファイル: Guzzle.php プロジェクト: alexanderkuz/test-yii2
 public function getAbsoluteUri($uri)
 {
     $build = parse_url($this->baseUri);
     $uriparts = parse_url(preg_replace('~^/+(?=/)~', '', $uri));
     if ($build === false) {
         throw new \Codeception\Exception\TestRuntime("URL '{$this->baseUri}' is malformed");
     } elseif ($uriparts === false) {
         throw new \Codeception\Exception\TestRuntime("URI '{$uri}' is malformed");
     }
     foreach ($uriparts as $part => $value) {
         if ($part === 'path' && strpos($value, '/') !== 0 && !empty($build[$part])) {
             $build[$part] = rtrim($build[$part], '/') . '/' . $value;
         } else {
             $build[$part] = $value;
         }
     }
     return \GuzzleHttp\Url::buildUrl($build);
 }
コード例 #3
0
 /**
  * Returns an absolute URL for the passed URI with the current URL
  * as the base path.
  *
  * @param string $uri the absolute or relative URI
  * @return string the absolute URL
  * @throws Codeception\Exception\TestRuntime if either the current
  *         URL or the passed URI can't be parsed
  */
 protected function getAbsoluteUrlFor($uri)
 {
     $currentUrl = $this->client->getHistory()->current()->getUri();
     if (empty($uri) || $uri === '#') {
         return $currentUrl;
     }
     $build = parse_url($currentUrl);
     $uriParts = parse_url($uri);
     if ($build === false) {
         throw new TestRuntime("URL '{$currentUrl}' is malformed");
     } elseif ($uriParts === false) {
         throw new TestRuntime("URI '{$uri}' is malformed");
     }
     $abs = $this->mergeUrls($build, $uriParts);
     return \GuzzleHttp\Url::buildUrl($abs);
 }
コード例 #4
0
ファイル: UrlTest.php プロジェクト: JREAMLU/timeline
 public function testAddsQueryIfPresent()
 {
     $this->assertEquals('?foo=bar', Url::buildUrl(array('query' => 'foo=bar')));
 }
コード例 #5
0
ファイル: Guzzle.php プロジェクト: nhemnhem/learning_test
 public function getAbsoluteUri($uri)
 {
     if ($uri && 0 !== strpos($uri, 'http') && $uri[0] !== '/' && $this->redirect) {
         $currentUri = $this->history->current()->getUri();
         $path = parse_url($currentUri, PHP_URL_PATH);
         if ('/' !== substr($path, -1)) {
             $path = substr($path, 0, strrpos($path, '/') + 1);
         }
         $uri = $path . $uri;
     }
     $build = parse_url($this->baseUri);
     $uriParts = parse_url(preg_replace('~^/+(?=/)~', '', $uri));
     if ($build === false) {
         throw new TestRuntimeException("URL '{$this->baseUri}' is malformed");
     } elseif ($uriParts === false) {
         throw new TestRuntimeException("URI '{$uri}' is malformed");
     }
     foreach ($uriParts as $part => $value) {
         if ($part === 'path' && strpos($value, '/') !== 0 && !empty($build[$part])) {
             $build[$part] = rtrim($build[$part], '/') . '/' . $value;
         } else {
             $build[$part] = $value;
         }
     }
     return \GuzzleHttp\Url::buildUrl($build);
 }
コード例 #6
0
 /**
  * @param \Symfony\Component\DomCrawler\Crawler $form
  *
  * @return string
  */
 protected function getFormUrl($form)
 {
     $action = $form->attr('action');
     $currentUrl = $this->client->getHistory()->current()->getUri();
     if (empty($action) || $action === '#') {
         return $currentUrl;
     }
     $build = parse_url($currentUrl);
     if ($build === false) {
         throw new TestRuntime("URL '{$currentUrl}' is malformed");
     }
     $uriParts = parse_url($action);
     if ($uriParts === false) {
         throw new TestRuntime("URI '{$action}' is malformed");
     }
     foreach ($uriParts as $part => $value) {
         if ($part === 'path' && strpos($value, '/') !== 0 && !empty($build[$part])) {
             // if it ends with a slash, relative paths are below it
             if (preg_match('~/$~', $build[$part])) {
                 $build[$part] = $build[$part] . $value;
                 continue;
             }
             $build[$part] = dirname($build[$part]) . '/' . $value;
             continue;
         }
         $build[$part] = $value;
     }
     return \GuzzleHttp\Url::buildUrl($build);
 }
コード例 #7
0
 private function transformToUploadUrl()
 {
     $parts = parse_url($this->request->getUrl());
     if (!isset($parts['path'])) {
         $parts['path'] = '';
     }
     $parts['path'] = '/upload' . $parts['path'];
     $url = Url::fromString(Url::buildUrl($parts));
     $this->request->setUrl($url);
 }
コード例 #8
0
 /**
  * Set base parameters of homepage url.
  *
  * @param string $homepage satis repository url
  */
 private function setUrlHelper($homepage)
 {
     $parsedUrl = Url::fromString($homepage)->getParts();
     if (isset($parsedUrl['user']) && isset($parsedUrl['pass'])) {
         $this->credentials = array('auth' => array($parsedUrl['user'], $parsedUrl['pass']));
     }
     if (isset($parsedUrl['path'])) {
         $this->basePath = $parsedUrl['path'];
         $this->basePath .= substr($this->basePath, -1) == '/' ? '' : '/';
     }
     $this->baseUrl = Url::buildUrl(array('scheme' => $parsedUrl['scheme'], 'host' => $parsedUrl['host'], 'port' => $parsedUrl['port']));
     return $this;
 }
コード例 #9
0
 private function coerceUri($uri)
 {
     if (is_null($uri)) {
         return null;
     } else {
         if (is_string($uri)) {
             return Url::fromString($uri);
         } else {
             if (is_array($uri)) {
                 return Url::buildUrl($uri);
             } else {
                 if (get_class($uri) == 'GuzzleHttp\\Url') {
                     return $uri;
                 } else {
                     throw new \InvalidArgumentException('unexpected type for a uri: ' . get_class($uri));
                 }
             }
         }
     }
 }
コード例 #10
0
ファイル: WebDriver.php プロジェクト: kansey/yii2albom
 public function amOnPage($page)
 {
     $build = parse_url($this->config['url']);
     $uriparts = parse_url($page);
     if ($build === false) {
         throw new \Codeception\Exception\TestRuntime("URL '{$this->config['url']}' is malformed");
     } elseif ($uriparts === false) {
         throw new \Codeception\Exception\TestRuntime("URI '{$page}' is malformed");
     }
     foreach ($uriparts as $part => $value) {
         if ($part === 'path' && !empty($build[$part])) {
             $build[$part] = rtrim($build[$part], '/') . '/' . ltrim($value, '/');
         } else {
             $build[$part] = $value;
         }
     }
     $this->webDriver->get(\GuzzleHttp\Url::buildUrl($build));
 }