/** * Create the request object * @param string $method * @param string $url * @param array $headers * @return AbstractRequest */ public function createRequest($method, $url = '', array $headers = []) { if (!is_string($url)) { throw new InvalidArgumentException('Url parameter must be a valid string!!'); } $url = new Url((isset($this->baseUrl) ? $this->baseUrl->toString() : '') . $url); $request = $this->requestFactory->build($method, $url, $headers); $request->setClient($this); return $request; }
/** * Build a new request from parameters * @param string $method * @param Url $url * @param array $headers * @return AbstractRequest * @throws UnknownProtocolException * @throws InvalidArgumentException */ public function build($method, Url $url, array $headers) { if (($scheme = self::isAllowedScheme((string) $url->scheme())) === false) { throw new UnknownProtocolException(sprintf("You can't request a transfer on unsupported protocol '%s'!", $url->scheme())); } $scheme = ucfirst($scheme); $name = __NAMESPACE__ . '\\' . $scheme . '\\' . ucfirst(strtolower($method)); if (!class_exists($name)) { throw new InvalidArgumentException('Method given is not a valid request: ' . $method); } $configurationClass = '\\Bee4\\Transport\\Configuration\\' . $scheme . 'Configuration'; $request = new $name($url, $headers, new $configurationClass($this->configuration !== null ? $this->configuration->toArray() : [])); return $request; }
/** * @param string $url */ public function __construct($url) { if (!is_string($url)) { throw new InvalidArgumentException('url given must be a valid string!'); } if (!Url::isValid($url)) { throw new InvalidArgumentException('url given is not a valid url (according to PHP FILTER_VALIDATE_URL). ' . $url); } //Define default entries if (($parsed = parse_url($url)) !== false) { foreach ($parsed as $name => $value) { $this->{$name}($value); } } }
/** * @expectedException \Bee4\Transport\Exception\InvalidArgumentException */ public function testSetInvalidFragment() { $url = new Url('http://www.bee4.fr'); $url->fragment(null); }