Completed
Push — EZP-31460 ( fb49b1...efa331 )
by
unknown
19:23 queued 11s
created

serializeSiteAccess()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 2
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
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
declare(strict_types=1);
8
9
namespace eZ\Bundle\EzPublishCoreBundle\Fragment;
10
11
use eZ\Publish\Core\MVC\Symfony\Component\Serializer\SerializerTrait;
12
use eZ\Publish\Core\MVC\Symfony\SiteAccess;
13
use Symfony\Component\HttpKernel\Controller\ControllerReference;
14
15
trait SiteAccessSerializationTrait
16
{
17
    use SerializerTrait;
18
19
    public function serializeSiteAccess(SiteAccess $siteAccess, ControllerReference $uri): void
20
    {
21
        // Serialize the siteaccess to get it back after. @see eZ\Publish\Core\MVC\Symfony\EventListener\SiteAccessMatchListener
22
        $uri->attributes['serialized_siteaccess'] = json_encode($siteAccess);
23
        $uri->attributes['serialized_siteaccess_matcher'] = $this->getSerializer()->serialize(
24
            $siteAccess->matcher,
25
            'json'
26
        );
27
        if ($siteAccess->matcher instanceof SiteAccess\Matcher\CompoundInterface) {
28
            $subMatchers = $siteAccess->matcher->getSubMatchers();
29
            foreach ($subMatchers as $subMatcher) {
30
                $uri->attributes['serialized_siteaccess_sub_matchers'][get_class($subMatcher)] = $this->getSerializer()->serialize(
31
                    $subMatcher,
32
                    'json'
33
                );
34
            }
35
        }
36
    }
37
}
38