Skip to content

Version 0.7.1

Latest
Compare
Choose a tag to compare
@wasinger wasinger released this 25 Jul 16:02
· 1 commit to master since this release

Compatibility with Psr\Http\Message\UriInterface (PSR-7)

  • class Url now has all methods defined in this interface but does not officially implement it.
  • new wrapper class Psr7Uri that implements UriInterface
  • methods for converting between Url and Psr7Uri

Class Url does not implement the PSR Interface by itself for two reasons:

  1. To not introduce a new dependency on the PSR interface. The dependency is only "suggested" in composer json.
  2. Because the PSR interface is designed to be immutable,
    while Url is not.

To use this feature, you need to composer require psr/http-message

<?php
use Wa72\Url\Psr7Uri;
use Wa72\Url\Url;

# Get a Psr7Uri from a Url object

$url = Url::parse('https://www.foo.bar/test.php?a=b');
$psr7uri = Psr7Uri::fromUrl($url);
// or alternatively:
$psr7uri = $url->toPsr7();

# Get a Url object from UriInterface

$url = Url::fromPsr7($psr7uri);
// or alternatively:
$url = $psr7uri->toUrl();