State::getMiddleware()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace MiladRahimi\PhpRouter\Routing;
4
5
/**
6
 * It is state (attributes) of routes
7
 */
8
class State
9
{
10
    private string $prefix;
11
12
    private array $middleware;
13
14
    private ?string $domain;
15
16
    /**
17
     * Constructor
18
     *
19
     * @param string $prefix
20
     * @param array $middleware
21
     * @param string|null $domain
22
     */
23
    public function __construct(string $prefix = '', array $middleware = [], ?string $domain = null)
24
    {
25
        $this->prefix = $prefix;
26
        $this->middleware = $middleware;
27
        $this->domain = $domain;
28
    }
29
30
    /**
31
     * Append new attributes to the existing ones
32
     */
33
    public function append(array $attributes): void
34
    {
35
        $this->domain = $attributes[Attributes::DOMAIN] ?? null;
36
        $this->prefix .= $attributes[Attributes::PREFIX] ?? '';
37
        $this->middleware = array_merge($this->middleware, $attributes[Attributes::MIDDLEWARE] ?? []);
38
    }
39
40
    public function getPrefix(): string
41
    {
42
        return $this->prefix;
43
    }
44
45
    public function getMiddleware(): array
46
    {
47
        return $this->middleware;
48
    }
49
50
    public function getDomain(): ?string
51
    {
52
        return $this->domain;
53
    }
54
}
55