|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
5
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
namespace eZ\Bundle\EzPublishCoreBundle\Fragment; |
|
8
|
|
|
|
|
9
|
|
|
use eZ\Publish\Core\MVC\Symfony\Component\Serializer\SerializerTrait; |
|
10
|
|
|
use eZ\Publish\Core\MVC\Symfony\SiteAccess\SiteAccessAware; |
|
11
|
|
|
use eZ\Publish\Core\MVC\Symfony\SiteAccess; |
|
12
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
13
|
|
|
use Symfony\Component\HttpKernel\Controller\ControllerReference; |
|
14
|
|
|
use Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface; |
|
15
|
|
|
use Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer as BaseRenderer; |
|
16
|
|
|
use Symfony\Component\HttpKernel\Fragment\RoutableFragmentRenderer; |
|
17
|
|
|
|
|
18
|
|
|
class InlineFragmentRenderer extends BaseRenderer implements SiteAccessAware |
|
19
|
|
|
{ |
|
20
|
|
|
use SerializerTrait; |
|
21
|
|
|
|
|
22
|
|
|
/** @var \Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface */ |
|
23
|
|
|
private $innerRenderer; |
|
24
|
|
|
|
|
25
|
|
|
/** @var \eZ\Publish\Core\MVC\Symfony\SiteAccess */ |
|
26
|
|
|
private $siteAccess; |
|
27
|
|
|
|
|
28
|
|
|
public function __construct(FragmentRendererInterface $innerRenderer) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->innerRenderer = $innerRenderer; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function setFragmentPath($path) |
|
34
|
|
|
{ |
|
35
|
|
|
if ($this->innerRenderer instanceof RoutableFragmentRenderer) { |
|
36
|
|
|
$this->innerRenderer->setFragmentPath($path); |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function setSiteAccess(SiteAccess $siteAccess = null) |
|
41
|
|
|
{ |
|
42
|
|
|
$this->siteAccess = $siteAccess; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function render($uri, Request $request, array $options = []) |
|
46
|
|
|
{ |
|
47
|
|
|
if ($uri instanceof ControllerReference) { |
|
48
|
|
View Code Duplication |
if ($request->attributes->has('siteaccess')) { |
|
|
|
|
|
|
49
|
|
|
/** @var \eZ\Publish\Core\MVC\Symfony\SiteAccess $siteAccess */ |
|
50
|
|
|
$siteAccess = $request->attributes->get('siteaccess'); |
|
51
|
|
|
$uri->attributes['serialized_siteaccess'] = json_encode($siteAccess); |
|
52
|
|
|
$uri->attributes['serialized_siteaccess_matcher'] = $this->getSerializer()->serialize( |
|
53
|
|
|
$siteAccess->matcher, |
|
54
|
|
|
'json' |
|
55
|
|
|
); |
|
56
|
|
|
if ($siteAccess->matcher instanceof SiteAccess\Matcher\CompoundInterface) { |
|
57
|
|
|
$subMatchers = $siteAccess->matcher->getSubMatchers() ?? null; |
|
58
|
|
|
foreach ($subMatchers as $subMatcher) { |
|
|
|
|
|
|
59
|
|
|
$uri->attributes['serialized_siteaccess_sub_matchers'][get_class($subMatcher)] = $this->getSerializer()->serialize( |
|
60
|
|
|
$subMatcher, |
|
61
|
|
|
'json' |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
if ($request->attributes->has('semanticPathinfo')) { |
|
67
|
|
|
$uri->attributes['semanticPathinfo'] = $request->attributes->get('semanticPathinfo'); |
|
68
|
|
|
} |
|
69
|
|
|
if ($request->attributes->has('viewParametersString')) { |
|
70
|
|
|
$uri->attributes['viewParametersString'] = $request->attributes->get('viewParametersString'); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return $this->innerRenderer->render($uri, $request, $options); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function getName() |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->innerRenderer->getName(); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.