Test Failed
Pull Request — master (#16)
by Divine Niiquaye
13:18
created

CompiledRoute   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 69
rs 10
c 1
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getRegex() 0 3 1
A __construct() 0 5 1
A serialize() 0 3 1
A getVariables() 0 3 1
A unserialize() 0 7 1
A getHostsRegex() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Flight Routing.
7
 *
8
 * PHP version 7.1 and above required
9
 *
10
 * @author    Divine Niiquaye Ibok <[email protected]>
11
 * @copyright 2019 Biurad Group (https://biurad.com/)
12
 * @license   https://opensource.org/licenses/BSD-3-Clause License
13
 *
14
 * For the full copyright and license information, please view the LICENSE
15
 * file that was distributed with this source code.
16
 */
17
18
namespace Flight\Routing;
19
20
/**
21
 * CompiledRoutes are returned by the RouteCompilerInterface instance.
22
 *
23
 * @author Divine Niiquaye Ibok <[email protected]>
24
 */
25
class CompiledRoute implements \Serializable
26
{
27
    /** @var string */
28
    private $pathRegex;
29
30
    /** @var string[] */
31
    private $hostRegexs;
32
33
    /** @var array */
34
    private $variables;
35
36
    /**
37
     * @param string   $pathRegex  The regular expression to use to match this route
38
     * @param string[] $hostRegexs A list of Host regexs
39
     * @param array    $variables  An array of variables (variables defined in the path and in the host patterns)
40
     */
41
    public function __construct(string $pathRegex, array $hostRegexs, array $variables)
42
    {
43
        $this->pathRegex = $pathRegex;
44
        $this->hostRegexs = $hostRegexs;
45
        $this->variables = $variables;
46
    }
47
48
    /**
49
     * @internal
50
     */
51
    final public function serialize(): string
52
    {
53
        return \serialize(['vars' => $this->variables, 'path_regex' => $this->pathRegex, 'host_regexs' => $this->hostRegexs]);
54
    }
55
56
    /**
57
     * @internal
58
     */
59
    final public function unserialize($data): void
60
    {
61
        $data = \unserialize($data, ['allowed_classes' => false]);
62
63
        $this->variables = $data['vars'];
64
        $this->hostRegexs = $data['host_regexs'];
65
        $this->pathRegex = $data['path_regex'];
66
    }
67
68
    /**
69
     * Returns the path regex.
70
     */
71
    public function getRegex(): string
72
    {
73
        return $this->pathRegex;
74
    }
75
76
    /**
77
     * Returns the hosts regex.
78
     *
79
     * @return string[] The hosts regex
80
     */
81
    public function getHostsRegex(): array
82
    {
83
        return $this->hostRegexs;
84
    }
85
86
    /**
87
     * Returns the compiled variables.
88
     *
89
     * @return array<string,string|null>
90
     */
91
    public function getVariables(): array
92
    {
93
        return $this->variables;
94
    }
95
}
96