Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

!!![TASK] Remove UrlGeneratorInterface::relativeURL #606

Merged
merged 1 commit into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use phpDocumentor\Guides\Nodes\Node;
use phpDocumentor\Guides\RestructuredText\Parser\Directive;
use phpDocumentor\Guides\RestructuredText\Parser\Productions\Rule;
use phpDocumentor\Guides\UrlGeneratorInterface;

/**
* Renders an image, example :
Expand All @@ -23,7 +22,7 @@
*/
class FigureDirective extends SubDirective
{
public function __construct(protected Rule $startingRule, private readonly UrlGeneratorInterface $urlGenerator)
public function __construct(protected Rule $startingRule)
{
parent::__construct($startingRule);
}
Expand All @@ -41,7 +40,7 @@ protected function processSub(
CollectionNode $collectionNode,
Directive $directive,
): Node|null {
$image = new ImageNode($this->urlGenerator->relativeUrl($directive->getData()));
$image = new ImageNode($directive->getData());
$scalarOptions = $this->optionsToArray($directive->getOptions());
$image = $image->withOptions([
'width' => $scalarOptions['width'] ?? null,
Expand Down
7 changes: 1 addition & 6 deletions packages/guides/src/ParserContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,14 @@ public function getLinks(): array
return $this->links;
}

private function relativeUrl(string $url): string
{
return $this->urlGenerator->relativeUrl($url);
}

public function absoluteRelativePath(string $url): string
{
$uri = Uri::createFromString($url);
if (UriInfo::isAbsolutePath($uri)) {
return $this->currentDirectory . '/' . ltrim($url, '/');
}

return $this->currentDirectory . '/' . $this->getDirName() . '/' . $this->relativeUrl($url);
return $this->currentDirectory . '/' . $this->getDirName() . '/' . ltrim($url, '/');
}

public function getDirName(): string
Expand Down
12 changes: 2 additions & 10 deletions packages/guides/src/RenderContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,11 @@ public function getVariable(string $variable, mixed $default = null): mixed
return $this->document->getVariable($variable, $default);
}

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

if ($link !== null) {
if ($relative) {
return $this->urlGenerator->relativeUrl($link);
}

return $link;
}

return '';
return $link ?? '';
}

public function canonicalUrl(string $url): string
Expand Down
18 changes: 0 additions & 18 deletions packages/guides/src/UrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,6 @@ public function absoluteUrl(string $basePath, string $url): string
return '/' . trim($basePath, '/') . '/' . $url;
}

/**
* Resolves a relative URL.
*/
public function relativeUrl(string $url): string
{
$uri = UriFactory::createUri($url);

if (UriInfo::isAbsolutePath($uri)) {
return $url;
}

if (UriInfo::isRelativePath($uri)) {
return $url;
}

return ltrim($url, '/');
}

/**
* Returns the Path used in the Metas to find this file.
*
Expand Down
5 changes: 0 additions & 5 deletions packages/guides/src/UrlGeneratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ interface UrlGeneratorInterface
*/
public function absoluteUrl(string $basePath, string $url): string;

/**
* Resolves a relative URL.
*/
public function relativeUrl(string $url): string;

/**
* Returns the Path used in the Metas to find this file.
*
Expand Down