Completed
Push — dev ( d8e2c0...b30194 )
by Андрей
02:16
created

Container::has()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 2
1
<?php
2
/**
3
 * @link    https://github.com/nnx-framework/container
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace Nnx\Container;
7
8
use Zend\ServiceManager\AbstractPluginManager;
9
use Zend\ServiceManager\ConfigInterface;
10
use Nnx\Container\EntryNameResolver\EntryNameResolverInterface;
11
12
/**
13
 * Class Container
14
 *
15
 * @package Nnx\Container
16
 */
17
class Container extends AbstractPluginManager implements ContainerInterface
18
{
19
    /**
20
     * Имя секции в конфиги приложения отвечающей за настройки контейнера
21
     *
22
     * @var string
23
     */
24
    const CONFIG_KEY = 'nnx_container';
25
26
    /**
27
     * Флаг определяющий нужно ли производить поиск по $id в связанных ServiceManager'ах
28
     *
29
     * @var bool
30
     */
31
    protected $flagUsePeeringServiceManagers = false;
32
33
    /**
34
     * Флаг определяет, нужно ли задействовать абстрактные фабрики, при поиске по $id
35
     *
36
     * @var bool
37
     */
38
    protected $flagCheckAbstractFactories = true;
39
40
    /**
41
     * Резолвер для получения имени создаваемой сущщности
42
     *
43
     * @var EntryNameResolverInterface
44
     */
45
    protected $entryNameResolver;
46
47
    /**
48
     * Container constructor.
49
     *
50
     * @param EntryNameResolverInterface $entryNameResolver
51
     * @param ConfigInterface|null       $configuration
52
     */
53
    public function __construct(EntryNameResolverInterface $entryNameResolver, ConfigInterface $configuration = null)
54
    {
55
        $this->setEntryNameResolver($entryNameResolver);
56
        parent::__construct($configuration);
57
    }
58
59
60
    /**
61
     * @inheritdoc
62
     *
63
     * @param string     $id
64
     * @param array|null $options
65
     * @param null       $context
66
     *
67
     * @return mixed
68
     */
69
    public function get($id, array $options = null, $context = null)
70
    {
71
        $resolvedId = $this->getEntryNameByContext($id, $context);
72
        $flagUsePeeringServiceManagers = $this->getFlagUsePeeringServiceManagers();
73
        return parent::get($resolvedId, $options, $flagUsePeeringServiceManagers);
0 ignored issues
show
Bug introduced by
It seems like $options defined by parameter $options on line 69 can also be of type null; however, Zend\ServiceManager\AbstractPluginManager::get() does only seem to accept array, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
74
    }
75
76
    /**
77
     * @inheritdoc
78
     *
79
     * @param array|string $id
80
     * @param null         $context
81
     *
82
     * @return bool|void
83
     *
84
     */
85
    public function has($id, $context = null)
86
    {
87
        $resolvedId = $this->getEntryNameByContext($id, $context);
0 ignored issues
show
Bug introduced by
It seems like $id defined by parameter $id on line 85 can also be of type array; however, Nnx\Container\Container::getEntryNameByContext() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
88
        $flagCheckAbstractFactories = $this->getFlagCheckAbstractFactories();
89
        $flagUsePeeringServiceManagers = $this->getFlagUsePeeringServiceManagers();
90
        return parent::has($resolvedId, $flagCheckAbstractFactories, $flagUsePeeringServiceManagers);
91
    }
92
93
    /**
94
     * @inheritdoc
95
     *
96
     * @param string $id
97
     * @param null   $context
98
     *
99
     * @return string|void
100
     */
101
    public function getEntryNameByContext($id, $context = null)
102
    {
103
        return $this->getEntryNameResolver()->resolveEntryNameByContext($id, $context);
104
    }
105
106
    /**
107
     * @inheritdoc
108
     *
109
     * @param mixed $plugin
110
     *
111
     * @return bool
112
     */
113
    public function validatePlugin($plugin)
114
    {
115
        return true;
116
    }
117
118
    /**
119
     * Возвращает флаг определяющий нужно ли производить поиск по $id в связанных ServiceManager'ах
120
     *
121
     * @return boolean
122
     */
123
    public function getFlagUsePeeringServiceManagers()
124
    {
125
        return $this->flagUsePeeringServiceManagers;
126
    }
127
128
    /**
129
     * Устанавливает флаг определяющий нужно ли производить поиск по $id в связанных ServiceManager'ах
130
     *
131
     * @param boolean $flagUsePeeringServiceManagers
132
     *
133
     * @return $this
134
     */
135
    public function setFlagUsePeeringServiceManagers($flagUsePeeringServiceManagers)
136
    {
137
        $this->flagUsePeeringServiceManagers = (bool)$flagUsePeeringServiceManagers;
138
139
        return $this;
140
    }
141
142
    /**
143
     * Возвращает флаг определяяющий, нужно ли задействовать абстрактные фабрики, при поиске по $id
144
     *
145
     * @return boolean
146
     */
147
    public function getFlagCheckAbstractFactories()
148
    {
149
        return $this->flagCheckAbstractFactories;
150
    }
151
152
    /**
153
     * Устанавливает флаг определяяющий, нужно ли задействовать абстрактные фабрики, при поиске по $id
154
     *
155
     * @param boolean $flagCheckAbstractFactories
156
     *
157
     * @return $this
158
     */
159
    public function setFlagCheckAbstractFactories($flagCheckAbstractFactories)
160
    {
161
        $this->flagCheckAbstractFactories = (bool)$flagCheckAbstractFactories;
162
163
        return $this;
164
    }
165
166
    /**
167
     * Возвращает резолвер для получения имени создаваемой сущщности
168
     *
169
     * @return EntryNameResolverInterface
170
     */
171
    public function getEntryNameResolver()
172
    {
173
        return $this->entryNameResolver;
174
    }
175
176
    /**
177
     * Устанавливает резолвер для получения имени создаваемой сущщности
178
     *
179
     * @param EntryNameResolverInterface $entryNameResolver
180
     *
181
     * @return $this
182
     */
183
    public function setEntryNameResolver($entryNameResolver)
184
    {
185
        $this->entryNameResolver = $entryNameResolver;
186
187
        return $this;
188
    }
189
}
190