Skip to content

Commit

Permalink
Add support for Stringable object in interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Jul 13, 2023
1 parent f00d9e6 commit 1256bc2
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 24 deletions.
5 changes: 3 additions & 2 deletions Contracts/AuthorityInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use League\Uri\Exceptions\IdnSupportMissing;
use League\Uri\Exceptions\SyntaxError;
use Stringable;

interface AuthorityInterface extends UriComponentInterface
{
Expand Down Expand Up @@ -48,7 +49,7 @@ public function getUserInfo(): ?string;
* requiring IDN support when IDN support is not present
* or misconfigured.
*/
public function withHost(?string $host): self;
public function withHost(Stringable|string|null $host): self;

/**
* Return an instance with the specified port.
Expand Down Expand Up @@ -77,5 +78,5 @@ public function withPort(?int $port): self;
* @throws SyntaxError for invalid component or transformations
* that would result in an object in invalid state.
*/
public function withUserInfo(?string $user, ?string $password = null): self;
public function withUserInfo(Stringable|string|null $user, Stringable|string|null $password = null): self;
}
3 changes: 2 additions & 1 deletion Contracts/DataPathInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace League\Uri\Contracts;

use SplFileObject;
use Stringable;

interface DataPathInterface extends PathInterface
{
Expand Down Expand Up @@ -90,5 +91,5 @@ public function toAscii(): self;
*
* An empty parameters value is equivalent to removing the parameter.
*/
public function withParameters(string $parameters): self;
public function withParameters(Stringable|string $parameters): self;
}
7 changes: 4 additions & 3 deletions Contracts/DomainHostInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Iterator;
use IteratorAggregate;
use League\Uri\Exceptions\SyntaxError;
use Stringable;

/**
* @extends IteratorAggregate<string>
Expand Down Expand Up @@ -57,12 +58,12 @@ public function isAbsolute(): bool;
/**
* Prepends a label to the host.
*/
public function prepend(string $label): self;
public function prepend(Stringable|string $label): self;

/**
* Appends a label to the host.
*/
public function append(string $label): self;
public function append(Stringable|string $label): self;

/**
* Returns an instance with its Root label.
Expand All @@ -89,7 +90,7 @@ public function withoutRootLabel(): self;
*
* @throws SyntaxError If the key is invalid
*/
public function withLabel(int $key, string $label): self;
public function withLabel(int $key, Stringable|string $label): self;

/**
* Returns an instance without the specified label.
Expand Down
9 changes: 5 additions & 4 deletions Contracts/QueryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Countable;
use Iterator;
use IteratorAggregate;
use Stringable;

/**
* @extends IteratorAggregate<array{0:string, 1:string|null}>
Expand Down Expand Up @@ -145,7 +146,7 @@ public function withSeparator(string $separator): self;
*
* @see ::withPair
*/
public function merge(string $query): self;
public function merge(Stringable|string $query): self;

/**
* Returns an instance with the new pairs appended to it.
Expand All @@ -155,15 +156,15 @@ public function merge(string $query): self;
*
* If the pair already exists the value will be added to it.
*/
public function append(string $query): self;
public function append(Stringable|string $query): self;

/**
* Returns a new instance with a specified key/value pair appended as a new pair.
*
* This method MUST retain the state of the current instance, and return
* an instance that contains the modified query
*/
public function appendTo(string $key, ?string $value): self;
public function appendTo(string $key, Stringable|string|int|bool|null $value): self;

/**
* Sorts the query string by offset, maintaining offset to data correlations.
Expand Down Expand Up @@ -216,7 +217,7 @@ public function withoutNumericIndices(): self;
*
* @see https://url.spec.whatwg.org/#dom-urlsearchparams-set
*/
public function withPair(string $key, string|int|null $value): self;
public function withPair(string $key, Stringable|string|int|null $value): self;

/**
* Returns an instance without the specified keys.
Expand Down
13 changes: 7 additions & 6 deletions Contracts/SegmentedPathInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Iterator;
use IteratorAggregate;
use League\Uri\Exceptions\SyntaxError;
use Stringable;

/**
* @extends IteratorAggregate<string>
Expand Down Expand Up @@ -70,12 +71,12 @@ public function keys(?string $segment = null): array;
/**
* Appends a segment to the path.
*/
public function append(string $segment): self;
public function append(Stringable|string $segment): self;

/**
* Prepends a segment to the path.
*/
public function prepend(string $segment): self;
public function prepend(Stringable|string $segment): self;

/**
* Returns an instance with the modified segment.
Expand All @@ -88,7 +89,7 @@ public function prepend(string $segment): self;
*
* @throws SyntaxError If the key is invalid
*/
public function withSegment(int $key, ?string $segment): self;
public function withSegment(int $key, Stringable|string|null $segment): self;

/**
* Returns an instance without the specified segment.
Expand Down Expand Up @@ -118,21 +119,21 @@ public function withoutEmptySegments(): self;
* This method MUST retain the state of the current instance, and return
* an instance that contains the extension basename modified.
*/
public function withDirname(string $path): self;
public function withDirname(Stringable|string $path): self;

/**
* Returns an instance with the specified basename.
*
* This method MUST retain the state of the current instance, and return
* an instance that contains the extension basename modified.
*/
public function withBasename(string $basename): self;
public function withBasename(Stringable|string $basename): self;

/**
* Returns an instance with the specified basename extension.
*
* This method MUST retain the state of the current instance, and return
* an instance that contains the extension basename modified.
*/
public function withExtension(string $extension): self;
public function withExtension(Stringable|string $extension): self;
}
12 changes: 6 additions & 6 deletions Contracts/UriInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public function getFragment(): ?string;
* @throws SyntaxError for invalid component or transformations
* that would result in an object in invalid state.
*/
public function withScheme(?string $scheme): self;
public function withScheme(Stringable|string|null $scheme): self;

/**
* Return an instance with the specified user information.
Expand All @@ -201,7 +201,7 @@ public function withScheme(?string $scheme): self;
* @throws SyntaxError for invalid component or transformations
* that would result in an object in invalid state.
*/
public function withUserInfo(?string $user, ?string $password = null): self;
public function withUserInfo(Stringable|string|null $user, Stringable|string|null $password = null): self;

/**
* Return an instance with the specified host.
Expand All @@ -218,7 +218,7 @@ public function withUserInfo(?string $user, ?string $password = null): self;
* requiring IDN support when IDN support is not present
* or misconfigured.
*/
public function withHost(?string $host): self;
public function withHost(Stringable|string|null $host): self;

/**
* Return an instance with the specified port.
Expand Down Expand Up @@ -250,7 +250,7 @@ public function withPort(?int $port): self;
* @throws SyntaxError for invalid component or transformations
* that would result in an object in invalid state.
*/
public function withPath(string $path): self;
public function withPath(Stringable|string $path): self;

/**
* Return an instance with the specified query string.
Expand All @@ -267,7 +267,7 @@ public function withPath(string $path): self;
* @throws SyntaxError for invalid component or transformations
* that would result in an object in invalid state.
*/
public function withQuery(?string $query): self;
public function withQuery(Stringable|string|null $query): self;

/**
* Return an instance with the specified URI fragment.
Expand All @@ -284,5 +284,5 @@ public function withQuery(?string $query): self;
* @throws SyntaxError for invalid component or transformations
* that would result in an object in invalid state.
*/
public function withFragment(?string $fragment): self;
public function withFragment(Stringable|string|null $fragment): self;
}
6 changes: 4 additions & 2 deletions Contracts/UserInfoInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace League\Uri\Contracts;

use Stringable;

interface UserInfoInterface extends UriComponentInterface
{
/**
Expand All @@ -34,7 +36,7 @@ public function getPass(): ?string;
*
* A variable equal to null is equivalent to removing the complete user information.
*/
public function withUser(?string $username): self;
public function withUser(Stringable|string|null $username): self;

/**
* Returns an instance with the specified user and/or pass.
Expand All @@ -45,5 +47,5 @@ public function withUser(?string $username): self;
*
* An empty user is equivalent to removing the user information.
*/
public function withPass(?string $password): self;
public function withPass(Stringable|string|null $password): self;
}

0 comments on commit 1256bc2

Please sign in to comment.