Completed
Push — master ( 016462...116ca6 )
by Anton
08:29 queued 06:32
created

Item::getUri()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
9
namespace Spiral\Vault\Models;
10
11
use Psr\Http\Message\UriInterface;
12
use Spiral\Core\Component;
13
use Spiral\Translator\Traits\TranslatorTrait;
14
use Spiral\Vault\Vault;
15
16
class Item extends Component
17
{
18
    use TranslatorTrait;
19
20
    /**
21
     * @var Vault
22
     */
23
    private $vault;
24
25
    /**
26
     * @var string
27
     */
28
    private $target = '';
29
30
    /**
31
     * @var array
32
     */
33
    private $item = [
34
        'title'    => '',
35
        'badge'    => '',
36
        'requires' => '',
37
    ];
38
39
    /**
40
     * @param string $target
41
     * @param array  $options
42
     */
43
    public function __construct(Vault $vault, string $target, array $options)
44
    {
45
        $this->vault = $vault;
46
        $this->target = $target;
47
        $this->item = $options;
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    public function getTarget(): string
54
    {
55
        return $this->target;
56
    }
57
58
    /**
59
     * @return string
60
     */
61
    public function getTitle(): string
62
    {
63
        return $this->say($this->item['title']);
64
    }
65
66
    /**
67
     * @return UriInterface
68
     */
69
    public function getUri(): UriInterface
70
    {
71
        return $this->vault->uri($this->getTarget());
72
    }
73
74
    /**
75
     * Check if item is visible.
76
     *
77
     * @return bool
78
     */
79
    public function isVisible(): bool
80
    {
81
        return $this->vault->getGuard()->allows(
82
            "{$this->vault->getConfig()->guardNamespace()}.{$this->getTarget()}"
83
        );
84
    }
85
}