Skip to content

Commit b3f0c11

Browse files
committed
Restore RestLocation.php
out of scope
1 parent 8746a41 commit b3f0c11

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace App\Rest\ValueObjectVisitor;
4+
5+
use Ibexa\Contracts\Core\Repository\URLAliasService;
6+
use Ibexa\Contracts\Rest\Output\Generator;
7+
use Ibexa\Contracts\Rest\Output\Visitor;
8+
use Ibexa\Rest\Server\Output\ValueObjectVisitor\RestLocation as BaseRestLocation;
9+
use Ibexa\Rest\Server\Values\URLAliasRefList;
10+
11+
class RestLocation extends BaseRestLocation
12+
{
13+
private URLAliasService $urlAliasService;
14+
15+
public function __construct(URLAliasService $urlAliasService)
16+
{
17+
$this->urlAliasService = $urlAliasService;
18+
}
19+
20+
public function visit(Visitor $visitor, Generator $generator, $data)
21+
{
22+
// Not using $generator->startObjectElement to not have the XML Generator adding its own media-type attribute with the default vendor
23+
$generator->startHashElement('Location');
24+
$generator->attribute(
25+
'media-type',
26+
'application/app.api.Location+' . strtolower((new \ReflectionClass($generator))->getShortName())
27+
);
28+
$generator->attribute(
29+
'href',
30+
$this->router->generate(
31+
'ibexa.rest.load_location',
32+
['locationPath' => trim($data->location->pathString, '/')]
33+
)
34+
);
35+
parent::visit($visitor, $generator, $data);
36+
$visitor->visitValueObject(new URLAliasRefList(array_merge(
37+
$this->urlAliasService->listLocationAliases($data->location, false),
38+
$this->urlAliasService->listLocationAliases($data->location, true)
39+
), $this->router->generate(
40+
'ibexa.rest.list_location_url_aliases',
41+
['locationPath' => trim($data->location->pathString, '/')]
42+
)));
43+
$generator->endHashElement('Location');
44+
}
45+
}

0 commit comments

Comments
 (0)