-
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
205 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
Neos.Neos/Classes/FrontendRouting/NodeUriSpecification.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Neos\Neos\FrontendRouting; | ||
|
||
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry; | ||
use Neos\Flow\Annotations as Flow; | ||
use Neos\Flow\Mvc\ActionRequest; | ||
use Neos\Flow\Mvc\Routing\Dto\RouteParameters; | ||
use Neos\Neos\Domain\Repository\SiteRepository; | ||
use Psr\Http\Message\UriInterface; | ||
|
||
#[Flow\Scope('singleton')] | ||
class NodeUriBuilder | ||
{ | ||
/** | ||
* If a uri is cross-linked to another cr than the one in the current request, the resulting uri will still be absolute and contain the host of the other site. | ||
*/ | ||
public function uriFor(NodeUriSpecification $specification, NodeUriResolveContext $context): UriInterface; | ||
|
||
/** | ||
* Will always return an absolute uri. | ||
* For nodes of the current cr (by request) it will use the current base uri. For foreign nodes the host will be inferred by the site entity. | ||
*/ | ||
public function absoluteUriFor(NodeUriSpecification $specification, NodeUriResolveContext $context): UriInterface; | ||
|
||
/** | ||
* Will resolve a relative uri with fully qualified node encoded. | ||
*/ | ||
public function previewUriFor(NodeUriSpecification $specification): UriInterface; | ||
} | ||
|
||
final readonly class NodeUriResolveContext | ||
{ | ||
public function __construct( | ||
UriInterface $baseUri, | ||
RouteParameters $routeParameters | ||
) { | ||
} | ||
|
||
public static function fromActionRequest(ActionRequest $request): self; | ||
} | ||
|
||
|
||
final readonly class NodeUriSpecification | ||
{ | ||
public function __construct( | ||
public NodeIdentity $node, | ||
public string $format, | ||
public array $routingArguments, | ||
public array $queryParameters, | ||
) { | ||
} | ||
} | ||
|
||
/** | ||
* Must be used with named arguments. | ||
*/ | ||
public static function create( | ||
?bool $absolute = null, | ||
?string $format = null, | ||
?array $routingArguments = null, | ||
?array $queryParameters = null | ||
) { | ||
return new self( | ||
$absolute ?? false, | ||
$format ?? '', | ||
$routingArguments ?? [], | ||
$queryParameters ?? [], | ||
); | ||
} | ||
|
||
public static function fromActionRequest(ActionRequest $request): self | ||
{ | ||
return self::create(format: $request->getFormat()); | ||
} | ||
|
||
/** | ||
* Must be used with named arguments. | ||
*/ | ||
public function with( | ||
?bool $absolute = null, | ||
?string $format = null, | ||
?array $routingArguments = null, | ||
?array $queryParameters = null | ||
) { | ||
return new self( | ||
$absolute ?? $this->absolute, | ||
$format ?? $this->format, | ||
$routingArguments ?? $this->routingArguments, | ||
$queryParameters ?? $this->queryParameters, | ||
); | ||
} | ||
} |