Skip to content

Commit

Permalink
Uri::create renamed Uri::createFromBaseUri
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Jun 1, 2019
1 parent 495dccd commit 46576c6
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 24 deletions.
15 changes: 12 additions & 3 deletions CHANGELOG.md
Expand Up @@ -8,19 +8,29 @@ All Notable changes to `League\Uri` will be documented in this file

- `League\Uri\UriInfo`: to get RFC3986 information from an URI object
- `League\Uri\UriResolver`: to resolve or relativize an URI object
- `League\Uri\UriString`: to parse or build an URL into or from its component
- `League\Uri\UriString`: to parse or build an URL into or from its components
- `League\Uri\Uri::createFromBaseUri` named constructor
- `League\Uri\Uri::createFromDataPath` named constructor
- `League\Uri\Uri::createFromPsr7` named constructor
- `League\Uri\Uri::createFromUnixPath` named constructor
- `League\Uri\Uri::createFromWindowsPath` named constructor
- `League\Uri\Http::createFromBaseUri` named constructor

### Fixed

- Improve parsing and building URI
- All URI object are now finals and supports parameter type widening
- `League\Uri\Uri` implements the `JsonSerializable` interface
- `League\Uri\Http` implements the `JsonSerializable` interface

### Deprecated

- None

### Remove

- support for PHP7.1 and PHP7.0
- `create` function defined in the `League\Uri` namespace replaced by `League\Uri\Uri::createFromBaseUri`
- `League\Uri\Factory` replaced by `League\Uri\Uri`
- `League\Uri\Data` replaced by `League\Uri\Uri`
- `League\Uri\File` replaced by `League\Uri\Uri`
Expand All @@ -29,8 +39,7 @@ All Notable changes to `League\Uri` will be documented in this file
- `League\Uri\UriException` replaced by `League\Uri\Contract\UriException`
- `League\Uri\AbstractUri` internal, replaced by `League\Uri\Uri`
- `League\Uri\Schemes` namespace and all classes inside
- all functions defined in the `League\Uri` namespace replaced by `League\Uri\Uri::create` public static method
- support for PHP7.1 and PHP7.0
- `League\Uri\Uri` no longer implements `League\Uri\UriInterface`

## 5.3.0 - 2018-03-14

Expand Down
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -27,7 +27,9 @@ Full documentation can be found at [uri.thephpleague.com][].
System Requirements
-------

You require **PHP >= 7.2** but the latest stable version of PHP is recommended.
You need **PHP >= 7.2** but the latest stable version of PHP is recommended

In order to handle IDN host you are required to also install the `intl` extension otherwise an exception will be thrown when attempting to validate such host.

Dependencies
-------
Expand Down
1 change: 0 additions & 1 deletion phpstan.src.neon
Expand Up @@ -3,5 +3,4 @@ includes:
- vendor/phpstan/phpstan-phpunit/rules.neon
parameters:
ignoreErrors:
- '#Method League\\Uri\\Uri::create\(\) should return League\\Uri\\Contract\\UriInterface but returns League\\Uri\\Contract\\UriInterface\|Psr\\Http\\Message\\UriInterface.#'
reportUnmatchedIgnoredErrors: true
4 changes: 2 additions & 2 deletions src/Http.php
Expand Up @@ -102,9 +102,9 @@ public static function createFromServer(array $server): self
* @param mixed $uri the input URI to create
* @param mixed $base_uri the base URI used for reference
*/
public static function create($uri, $base_uri = null): self
public static function createFromBaseUri($uri, $base_uri = null): self
{
return new self(Uri::create($uri, $base_uri));
return new self(Uri::createFromBaseUri($uri, $base_uri));
}

/**
Expand Down
12 changes: 9 additions & 3 deletions src/Uri.php
Expand Up @@ -538,7 +538,7 @@ public static function __set_state(array $components): self
* @param mixed $uri the input URI to create
* @param mixed $base_uri the base URI used for reference
*/
public static function create($uri, $base_uri = null): UriInterface
public static function createFromBaseUri($uri, $base_uri = null): UriInterface
{
if (!$uri instanceof UriInterface) {
$uri = self::createFromString($uri);
Expand All @@ -553,7 +553,10 @@ public static function create($uri, $base_uri = null): UriInterface
return $uri;
}

return UriResolver::resolve($uri, $uri->withFragment(null)->withQuery(null)->withPath(''));
/** @var UriInterface $uri */
$uri = UriResolver::resolve($uri, $uri->withFragment(null)->withQuery(null)->withPath(''));

return $uri;
}

if (!$base_uri instanceof UriInterface) {
Expand All @@ -564,7 +567,10 @@ public static function create($uri, $base_uri = null): UriInterface
throw new SyntaxError(sprintf('the base URI `%s` must be absolute', (string) $base_uri));
}

return UriResolver::resolve($uri, $base_uri);
/** @var UriInterface $uri */
$uri = UriResolver::resolve($uri, $base_uri);

return $uri;
}

/**
Expand Down
22 changes: 11 additions & 11 deletions tests/FactoryTest.php
Expand Up @@ -356,13 +356,13 @@ public function testFailCreateFromServerWithoutInvalidUserInfo(): void
}

/**
* @covers ::create
* @covers ::createFromBaseUri
*
* @dataProvider createProvider
*/
public function testCreate(string $base_uri, string $uri, string $expected): void
public function testCreateFromBaseUri(string $base_uri, string $uri, string $expected): void
{
self::assertSame($expected, (string) Uri::create($uri, $base_uri));
self::assertSame($expected, (string) Uri::createFromBaseUri($uri, $base_uri));
}
public function createProvider(): array
{
Expand Down Expand Up @@ -412,42 +412,42 @@ public function createProvider(): array
}

/**
* @covers ::create
* @covers ::createFromBaseUri
*/
public function testCreateThrowExceptionWithBaseUriNotAbsolute(): void
{
self::expectException(SyntaxError::class);
Uri::create('/path/to/you', '//example.com');
Uri::createFromBaseUri('/path/to/you', '//example.com');
}

/**
* @covers ::create
* @covers ::createFromBaseUri
*/
public function testCreateThrowExceptionWithUriNotAbsolute(): void
{
self::expectException(SyntaxError::class);
Uri::create('/path/to/you');
Uri::createFromBaseUri('/path/to/you');
}

/**
* @covers ::create
* @covers ::createFromBaseUri
*/
public function testCreateWithUriWithoutAuthority(): void
{
self::assertSame(
'data:text/plain;charset=us-ascii,',
(string) Uri::create('data:text/plain;charset=us-ascii,')
(string) Uri::createFromBaseUri('data:text/plain;charset=us-ascii,')
);
}

/**
* @covers ::create
* @covers ::createFromBaseUri
*/
public function testCreateWithAbasoluteUriWithoutBaseUri(): void
{
self::assertSame(
'scheme://host/sky?q#f',
(string) Uri::create('scheme://host/path/../sky?q#f')
(string) Uri::createFromBaseUri('scheme://host/path/../sky?q#f')
);
}
}
6 changes: 3 additions & 3 deletions tests/HttpTest.php
Expand Up @@ -128,13 +128,13 @@ public function testCreateFromComponents(): void
}

/**
* @covers ::create
* @covers ::createFromBaseUri
*/
public function testCreate(): void
public function testCreateFromBaseUri(): void
{
self::assertEquals(
Http::createFromString('http://0:0@0/0?0#0'),
Http::create('0?0#0', 'http://0:0@0/')
Http::createFromBaseUri('0?0#0', 'http://0:0@0/')
);
}

Expand Down

0 comments on commit 46576c6

Please sign in to comment.