Completed
Push — master ( 6a996d...b41795 )
by Mathieu
13:00 queued 10:14
created

AbstractUiItem::active()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Charcoal\Ui;
4
5
use InvalidArgumentException;
6
7
// From PSR-3 (Logger)
8
use Psr\Log\LoggerAwareInterface;
9
use Psr\Log\LoggerAwareTrait;
10
use Psr\Log\NullLogger;
11
12
use Pimple\Container;
13
14
// From 'charcoal-config'
15
use Charcoal\Config\AbstractEntity;
16
17
// From 'charcoal-translator'
18
use Charcoal\Translator\TranslatorAwareTrait;
19
20
// From 'charcoal-user'
21
use Charcoal\User\AuthAwareInterface;
22
use Charcoal\User\AuthAwareTrait;
23
24
// From 'charcoal-view'
25
use Charcoal\View\ViewableInterface;
26
use Charcoal\View\ViewableTrait;
27
28
// Intra-module ('charcoal-ui') dependencies
29
use Charcoal\Ui\UiItemInterface;
30
use Charcoal\Ui\UiItemTrait;
31
32
/**
33
 * An abstract UI Item.
34
 *
35
 * Abstract implementation of {@see \Charcoal\Ui\UiItemInterface}.
36
 */
37
abstract class AbstractUiItem extends AbstractEntity implements
38
    AuthAwareInterface,
39
    LoggerAwareInterface,
40
    UiItemInterface
41
{
42
    use AuthAwareTrait;
43
    use LoggerAwareTrait;
44
    use TranslatorAwareTrait;
45
    use UiItemTrait;
46
    use ViewableTrait;
47
48
49
    /**
50
     * Return a new UI item.
51
     *
52
     * @param array|\ArrayAccess $data The class depdendencies.
53
     */
54
    public function __construct(array $data = null)
55
    {
56
        if (!isset($data['logger'])) {
57
            $data['logger'] = new NullLogger();
58
        }
59
        $this->setLogger($data['logger']);
60
61
        if (isset($data['container'])) {
62
            $this->setDependencies($data['container']);
63
        }
64
    }
65
66
    /**
67
     * Inject dependencies from a DI Container.
68
     *
69
     * @param  Container $container A dependencies container instance.
70
     * @return void
71
     */
72
    public function setDependencies(Container $container)
73
    {
74
        $this->setTranslator($container['translator']);
75
        $this->setAuthenticator($container['authenticator']);
76
        $this->setAuthorizer($container['authorizer']);
77
    }
78
}
79