Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Commit

Permalink
Fix PsrUri to compatibility to Psr7 interface and Guzzle. Fixed #1.
Browse files Browse the repository at this point in the history
  • Loading branch information
asika32764 committed Aug 7, 2015
1 parent 7b32508 commit f2aea6d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function __construct($uri = null, $method = null, $body = 'php://memory',

if (!$uri instanceof UriInterface)
{
$uri = new PsrUri($uri);
$uri = new PsrUri((string) $uri);
}

foreach ($headers as $name => $value)
Expand Down
6 changes: 3 additions & 3 deletions src/Transport/AbstractTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public function __construct($options = array())
public function request(RequestInterface $request)
{
$uri = $request->getUri()
->withPath(null)
->withQuery(null)
->withFragment(null);
->withPath('')
->withQuery('')
->withFragment('');

$uri = $uri . $request->getRequestTarget();

Expand Down
26 changes: 22 additions & 4 deletions src/Uri/PsrUri.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@ class PsrUri extends AbstractUri implements PsrUriInterface
'sftp' => 22
);

/**
* Constructor.
* You can pass a URI string to the constructor to initialise a specific URI.
*
* @param string $uri The optional URI string
*
* @since 2.0
*/
public function __construct($uri = '')
{
if (!is_string($uri))
{
throw new \InvalidArgumentException('URI should be a string');
}

parent::__construct($uri);
}

/**
* Retrieve the authority component of the URI.
*
Expand Down Expand Up @@ -222,9 +240,9 @@ public function withPort($port)
*/
public function withPath($path)
{
if (is_array($path) || (is_object($path) && !is_callable($path, '__toString')))
if (!is_string($path))
{
throw new \InvalidArgumentException('Invalid path type.');
throw new \InvalidArgumentException('URI Path should be a string');
}

$path = (string) $path;
Expand Down Expand Up @@ -261,9 +279,9 @@ public function withPath($path)
*/
public function withQuery($query)
{
if (is_array($query))
if (!is_string($query))
{
$query = UriHelper::buildQuery($query);
throw new \InvalidArgumentException('URI query should be a string or array');
}

$query = UriHelper::filterQuery($query);
Expand Down

0 comments on commit f2aea6d

Please sign in to comment.