Skip to content

Commit f700ff0

Browse files
committed
Support leauge/uri 7.6
1 parent ddc4b5f commit f700ff0

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

src/Uri/IncludePathBuilder.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,34 @@
44

55
namespace Soap\Wsdl\Uri;
66

7-
use League\Uri\BaseUri;
87
use League\Uri\Modifier;
8+
use League\Uri\Uri;
9+
use function Psl\Str\starts_with;
910

1011
final class IncludePathBuilder
1112
{
1213
public static function build(string $relativePath, string $fromFile): string
1314
{
14-
return Modifier::from(BaseUri::from($fromFile)->resolve($relativePath))
15+
$baseUri = match(true) {
16+
starts_with($fromFile, '/') => Uri::fromUnixPath($fromFile),
17+
default => Uri::new($fromFile),
18+
};
19+
20+
$resolvedUri = $baseUri->resolve($relativePath);
21+
$modifier = Modifier::wrap($resolvedUri)
1522
->removeDotSegments()
16-
->removeEmptySegments()
17-
->getUri()
18-
->__toString()
19-
;
23+
->removeEmptySegments();
24+
25+
/**
26+
* @var Uri $relativeUri
27+
* @psalm-suppress UndefinedClass PHP's URI classes are only available from PHP 8.5
28+
*/
29+
$relativeUri = $modifier->unwrap();
30+
31+
if ($relativeUri->getScheme() === 'file') {
32+
return $relativeUri->getPath();
33+
}
34+
35+
return $relativeUri->toString();
2036
}
2137
}

tests/Unit/Uri/IncludePathBuilderTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ public static function provideBuildPaths()
2020
{
2121
yield 'same-dir-file' => [
2222
'relativePath' => 'otherfile.xml',
23-
'fromFile' => 'somedir/somefile.xml',
24-
'expected' => 'somedir/otherfile.xml',
23+
'fromFile' => '/somedir/somefile.xml',
24+
'expected' => '/somedir/otherfile.xml',
2525
];
2626
yield 'child-dir-file' => [
2727
'relativePath' => '../otherfile.xml',
28-
'fromFile' => 'somedir/child/somefile.xml',
29-
'expected' => 'somedir/otherfile.xml',
28+
'fromFile' => '/somedir/child/somefile.xml',
29+
'expected' => '/somedir/otherfile.xml',
3030
];
3131
yield 'http-file' => [
3232
'relativePath' => 'otherfile.xml',

0 commit comments

Comments
 (0)