-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathDecoratedFragmentRenderer.php
More file actions
87 lines (73 loc) · 3.01 KB
/
Copy pathDecoratedFragmentRenderer.php
File metadata and controls
87 lines (73 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace Ibexa\Bundle\Core\Fragment;
use Ibexa\Core\MVC\Symfony\SiteAccess;
use Ibexa\Core\MVC\Symfony\SiteAccess\SiteAccessAware;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ControllerReference;
use Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface;
use Symfony\Component\HttpKernel\Fragment\RoutableFragmentRenderer;
class DecoratedFragmentRenderer implements FragmentRendererInterface, SiteAccessAware
{
/** @var \Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface */
private $innerRenderer;
/** @var \Ibexa\Core\MVC\Symfony\SiteAccess */
private $siteAccess;
private SiteAccessSerializerInterface $siteAccessSerializer;
public function __construct(
FragmentRendererInterface $innerRenderer,
SiteAccessSerializerInterface $siteAccessSerializer
) {
$this->innerRenderer = $innerRenderer;
$this->siteAccessSerializer = $siteAccessSerializer;
}
/**
* @param \Ibexa\Core\MVC\Symfony\SiteAccess|null $siteAccess
*/
public function setSiteAccess(?SiteAccess $siteAccess = null)
{
$this->siteAccess = $siteAccess;
}
public function setFragmentPath($path)
{
if (!$this->innerRenderer instanceof RoutableFragmentRenderer) {
return null;
}
if ($this->siteAccess && $this->siteAccess->matcher instanceof SiteAccess\URILexer) {
$path = $this->siteAccess->matcher->analyseLink($path);
}
$this->innerRenderer->setFragmentPath($path);
}
/**
* Renders a URI and returns the Response content.
*
* @param string|\Symfony\Component\HttpKernel\Controller\ControllerReference $uri A URI as a string or a ControllerReference instance
* @param \Symfony\Component\HttpFoundation\Request $request A Request instance
* @param array $options An array of options
*
* @return \Symfony\Component\HttpFoundation\Response A Response instance
*/
public function render($uri, Request $request, array $options = [])
{
if ($uri instanceof ControllerReference && $request->attributes->has('siteaccess')) {
// Serialize a SiteAccess to get it back after.
// @see \Ibexa\Core\MVC\Symfony\EventListener\SiteAccessMatchListener
$siteAccess = $request->attributes->get('siteaccess');
$this->siteAccessSerializer->serializeSiteAccessAsControllerAttributes($siteAccess, $uri);
}
return $this->innerRenderer->render($uri, $request, $options);
}
/**
* Gets the name of the strategy.
*
* @return string The strategy name
*/
public function getName()
{
return $this->innerRenderer->getName();
}
}
class_alias(DecoratedFragmentRenderer::class, 'eZ\Bundle\EzPublishCoreBundle\Fragment\DecoratedFragmentRenderer');