Completed
Push — 6.13 ( fed935...f81640 )
by
unknown
25:12 queued 06:17
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
namespace eZ\Bundle\EzPublishCoreBundle\Fragment;
8
9
use eZ\Publish\Core\MVC\Symfony\Component\Serializer\SerializerTrait;
10
use eZ\Publish\Core\MVC\Symfony\SiteAccess;
11
use Symfony\Component\HttpKernel\Controller\ControllerReference;
12
13
trait SiteAccessSerializationTrait
14
{
15
    use SerializerTrait;
16
17
    public function serializeSiteAccess(SiteAccess $siteAccess, ControllerReference $uri)
18
    {
19
        // Serialize the siteaccess to get it back after. @see eZ\Publish\Core\MVC\Symfony\EventListener\SiteAccessMatchListener
20
        $uri->attributes['serialized_siteaccess'] = json_encode($siteAccess);
21
        $uri->attributes['serialized_siteaccess_matcher'] = $this->getSerializer()->serialize(
22
            $siteAccess->matcher,
23
            'json'
24
        );
25
        if ($siteAccess->matcher instanceof SiteAccess\Matcher\CompoundInterface) {
26
            $subMatchers = $siteAccess->matcher->getSubMatchers();
27
            foreach ($subMatchers as $subMatcher) {
28
                $uri->attributes['serialized_siteaccess_sub_matchers'][get_class($subMatcher)] = $this->getSerializer()->serialize(
29
                    $subMatcher,
30
                    'json'
31
                );
32
            }
33
        }
34
    }
35
}
36