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

SiteAccess::jsonSerialize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 10
rs 9.9332
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\Publish\Core\MVC\Symfony;
8
9
use eZ\Publish\API\Repository\Values\ValueObject;
10
use JsonSerializable;
11
12
/**
13
 * Base struct for a siteaccess representation.
14
 */
15
class SiteAccess extends ValueObject implements JsonSerializable
16
{
17
    /**
18
     * Name of the siteaccess.
19
     *
20
     * @var string
21
     */
22
    public $name;
23
24
    /**
25
     * The matching type that has been used to discover the siteaccess.
26
     * Contains the matcher class FQN, or 'default' if fell back to the default siteaccess.
27
     *
28
     * @var string
29
     */
30
    public $matchingType;
31
32
    /**
33
     * The matcher instance that has been used to discover the siteaccess.
34
     *
35
     * @var \eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher
36
     */
37
    public $matcher;
38
39
    public function __construct($name = null, $matchingType = null, $matcher = null)
40
    {
41
        $this->name = $name;
42
        $this->matchingType = $matchingType;
43
        $this->matcher = $matcher;
44
    }
45
46
    public function __toString()
47
    {
48
        return "$this->name (matched by '$this->matchingType')";
49
    }
50
51
    public function jsonSerialize()
52
    {
53
        $matcher = is_object($this->matcher) ? get_class($this->matcher) : null;
54
55
        return [
56
            'name' => $this->name,
57
            'matchingType' => $this->matchingType,
58
            'matcher' => $matcher,
59
        ];
60
    }
61
}
62