Skip to content

Commit d9d1a73

Browse files
authored
Merge pull request #606 from phpDocumentor/task/remove-relativeURL
!!![TASK] Remove UrlGeneratorInterface::relativeURL
2 parents 667fbd3 + e586c04 commit d9d1a73

File tree

5 files changed

+5
-42
lines changed

5 files changed

+5
-42
lines changed

packages/guides-restructured-text/src/RestructuredText/Directives/FigureDirective.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use phpDocumentor\Guides\Nodes\Node;
1111
use phpDocumentor\Guides\RestructuredText\Parser\Directive;
1212
use phpDocumentor\Guides\RestructuredText\Parser\Productions\Rule;
13-
use phpDocumentor\Guides\UrlGeneratorInterface;
1413

1514
/**
1615
* Renders an image, example :
@@ -23,7 +22,7 @@
2322
*/
2423
class FigureDirective extends SubDirective
2524
{
26-
public function __construct(protected Rule $startingRule, private readonly UrlGeneratorInterface $urlGenerator)
25+
public function __construct(protected Rule $startingRule)
2726
{
2827
parent::__construct($startingRule);
2928
}
@@ -41,7 +40,7 @@ protected function processSub(
4140
CollectionNode $collectionNode,
4241
Directive $directive,
4342
): Node|null {
44-
$image = new ImageNode($this->urlGenerator->relativeUrl($directive->getData()));
43+
$image = new ImageNode($directive->getData());
4544
$scalarOptions = $this->optionsToArray($directive->getOptions());
4645
$image = $image->withOptions([
4746
'width' => $scalarOptions['width'] ?? null,

packages/guides/src/ParserContext.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,14 @@ public function getLinks(): array
7070
return $this->links;
7171
}
7272

73-
private function relativeUrl(string $url): string
74-
{
75-
return $this->urlGenerator->relativeUrl($url);
76-
}
77-
7873
public function absoluteRelativePath(string $url): string
7974
{
8075
$uri = Uri::createFromString($url);
8176
if (UriInfo::isAbsolutePath($uri)) {
8277
return $this->currentDirectory . '/' . ltrim($url, '/');
8378
}
8479

85-
return $this->currentDirectory . '/' . $this->getDirName() . '/' . $this->relativeUrl($url);
80+
return $this->currentDirectory . '/' . $this->getDirName() . '/' . ltrim($url, '/');
8681
}
8782

8883
public function getDirName(): string

packages/guides/src/RenderContext.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,11 @@ public function getVariable(string $variable, mixed $default = null): mixed
8585
return $this->document->getVariable($variable, $default);
8686
}
8787

88-
public function getLink(string $name, bool $relative = true): string
88+
public function getLink(string $name): string
8989
{
9090
$link = $this->document->getLink($name);
9191

92-
if ($link !== null) {
93-
if ($relative) {
94-
return $this->urlGenerator->relativeUrl($link);
95-
}
96-
97-
return $link;
98-
}
99-
100-
return '';
92+
return $link ?? '';
10193
}
10294

10395
public function canonicalUrl(string $url): string

packages/guides/src/UrlGenerator.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,6 @@ public function absoluteUrl(string $basePath, string $url): string
4343
return '/' . trim($basePath, '/') . '/' . $url;
4444
}
4545

46-
/**
47-
* Resolves a relative URL.
48-
*/
49-
public function relativeUrl(string $url): string
50-
{
51-
$uri = UriFactory::createUri($url);
52-
53-
if (UriInfo::isAbsolutePath($uri)) {
54-
return $url;
55-
}
56-
57-
if (UriInfo::isRelativePath($uri)) {
58-
return $url;
59-
}
60-
61-
return ltrim($url, '/');
62-
}
63-
6446
/**
6547
* Returns the Path used in the Metas to find this file.
6648
*

packages/guides/src/UrlGeneratorInterface.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ interface UrlGeneratorInterface
1414
*/
1515
public function absoluteUrl(string $basePath, string $url): string;
1616

17-
/**
18-
* Resolves a relative URL.
19-
*/
20-
public function relativeUrl(string $url): string;
21-
2217
/**
2318
* Returns the Path used in the Metas to find this file.
2419
*

0 commit comments

Comments
 (0)