-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve UriTemplate interoperability with PSR-13
- Loading branch information
Showing
3 changed files
with
30 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
|
||
namespace League\Uri; | ||
|
||
use Deprecated; | ||
use League\Uri\Contracts\UriException; | ||
use League\Uri\Contracts\UriInterface; | ||
use League\Uri\Exceptions\SyntaxError; | ||
|
@@ -31,8 +32,10 @@ | |
* @package League\Uri | ||
* @author Ignace Nyamagana Butera <[email protected]> | ||
* @since 6.1.0 | ||
* | ||
* @phpstan-import-type InputValue from VariableBag | ||
*/ | ||
final class UriTemplate | ||
final class UriTemplate implements Stringable | ||
{ | ||
private readonly Template $template; | ||
private readonly VariableBag $defaultVariables; | ||
|
@@ -60,19 +63,27 @@ private function filterVariables(iterable $variables): VariableBag | |
)); | ||
} | ||
|
||
public function getTemplate(): string | ||
/** | ||
* Returns the string representation of the UriTemplate. | ||
*/ | ||
public function __toString(): string | ||
{ | ||
return $this->template->value; | ||
} | ||
|
||
/** | ||
* Returns the distinct variables placeholders used in the template. | ||
* | ||
* @return array<string> | ||
*/ | ||
public function getVariableNames(): array | ||
{ | ||
return $this->template->variableNames; | ||
} | ||
|
||
/** | ||
* @return array<string, InputValue> | ||
*/ | ||
public function getDefaultVariables(): array | ||
{ | ||
return iterator_to_array($this->defaultVariables); | ||
|
@@ -120,4 +131,19 @@ public function expandOrFail(iterable $variables = []): UriInterface | |
$this->filterVariables($variables)->replace($this->defaultVariables) | ||
)); | ||
} | ||
|
||
/** | ||
* DEPRECATION WARNING! This method will be removed in the next major point release. | ||
* | ||
* @deprecated Since version 7.6.0 | ||
* @codeCoverageIgnore | ||
* @see UriTemplate::toString() | ||
* | ||
* Create a new instance from the environment. | ||
*/ | ||
#[Deprecated(message:'use League\Uri\UriTemplate::__toString() instead', since:'league/uri:7.6.0')] | ||
public function getTemplate(): string | ||
{ | ||
return $this->__toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters