Completed
Push — 6.13 ( 7401a7...8452de )
by
unknown
18:35
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
 * File containing the SiteAccess class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\Core\MVC\Symfony;
10
11
use eZ\Publish\API\Repository\Values\ValueObject;
12
use JsonSerializable;
13
14
/**
15
 * Base struct for a siteaccess representation.
16
 */
17
class SiteAccess extends ValueObject implements JsonSerializable
18
{
19
    /**
20
     * Name of the siteaccess.
21
     *
22
     * @var string
23
     */
24
    public $name;
25
26
    /**
27
     * The matching type that has been used to discover the siteaccess.
28
     * Contains the matcher class FQN, or 'default' if fell back to the default siteaccess.
29
     *
30
     * @var string
31
     */
32
    public $matchingType;
33
34
    /**
35
     * The matcher instance that has been used to discover the siteaccess.
36
     *
37
     * @var \eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher
38
     */
39
    public $matcher;
40
41
    public function __construct($name = null, $matchingType = null, $matcher = null)
42
    {
43
        $this->name = $name;
44
        $this->matchingType = $matchingType;
45
        $this->matcher = $matcher;
46
    }
47
48
    public function __toString()
49
    {
50
        return "$this->name (matched by '$this->matchingType')";
51
    }
52
53
    public function jsonSerialize()
54
    {
55
        $matcher = is_object($this->matcher) ? get_class($this->matcher) : null;
56
57
        return [
58
            'name' => $this->name,
59
            'matchingType' => $this->matchingType,
60
            'matcher' => $matcher
61
        ];
62
    }
63
}
64