Issues (4)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Weew/Kernel/Kernel.php (4 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Weew\Kernel;
4
5
use Weew\Collections\Dictionary;
6
use Weew\Collections\IDictionary;
7
use Weew\Kernel\Exceptions\InvalidProviderException;
8
9
class Kernel implements IKernel {
10
    /**
11
     * @var array
12
     */
13
    protected $providers = [];
14
15
    /**
16
     * @var IProviderInvoker
17
     */
18
    protected $providerInvoker;
19
20
    /**
21
     * @var IDictionary
22
     */
23
    protected $sharedArguments;
24
25
    /**
26
     * @param IProviderInvoker|null $invoker
27
     */
28
    public function __construct(IProviderInvoker $invoker = null) {
29
        if ( ! $invoker instanceof IProviderInvoker) {
30
            $invoker = $this->createProviderInvoker();
31
        }
32
33
        $this->setSharedArguments($this->createSharedArguments());
34
        $this->setProviderInvoker($invoker);
35
    }
36
37
    /**
38
     * Instantiate all providers.
39
     *
40
     * @return void
41
     */
42
    public function create() {
43
        $this->createEach();
44
    }
45
46
    /**
47
     * Instantiate all providers.
48
     */
49
    protected function createEach() {
50
        foreach ($this->providers as $class => &$data) {
51
            if ( ! array_get($data, 'instance')) {
52
                $instance = $this->getProviderInvoker()
53
                    ->create($class, $this->getSharedArguments());
54
                array_set($data, 'instance', $instance);
55
56
                $this->create();
57
                break;
58
            }
59
        }
60
    }
61
62
    /**
63
     * Configure all providers.
64
     *
65
     * @return void
66
     */
67
    public function configure() {
68
        $this->configureEach();
69
    }
70
71
    /**
72
     * Configure all providers.
73
     *
74
     * @return void
75
     */
76 View Code Duplication
    protected function configureEach() {
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
77
        foreach ($this->providers as $class => &$data) {
78
            if ( ! array_contains(array_get($data, 'tags'), ProviderTag::CONFIGURED)) {
79
                $this->create();
80
81
                array_add($data, 'tags', ProviderTag::CONFIGURED);
82
                $instance = array_get($data, 'instance');
83
84
                if (method_exists($instance, 'configure')) {
85
                    $this->getProviderInvoker()
86
                        ->configure($instance, $this->getSharedArguments());
87
                }
88
89
                $this->configureEach();
90
                break;
91
            }
92
        }
93
    }
94
95
    /**
96
     * Initialize all providers.
97
     *
98
     * @return void
99
     */
100
    public function initialize() {
101
        $this->initializeEach();
102
    }
103
104
    /**
105
     * Initialize all providers.
106
     *
107
     * @return void
108
     */
109 View Code Duplication
    protected function initializeEach() {
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
110
        foreach ($this->providers as $class => &$data) {
111
            if ( ! array_contains(array_get($data, 'tags'), ProviderTag::INITIALIZED)) {
112
                $this->configure();
113
114
                array_add($data, 'tags', ProviderTag::INITIALIZED);
115
                $instance = array_get($data, 'instance');
116
117
                if (method_exists($instance, 'initialize')) {
118
                    $this->getProviderInvoker()
119
                        ->initialize($instance, $this->getSharedArguments());
120
                }
121
122
                $this->initializeEach();
123
                break;
124
            }
125
        }
126
    }
127
128
    /**
129
     * Boot all providers.
130
     *
131
     * @return void
132
     */
133
    public function boot() {
134
        $this->bootEach();
135
    }
136
137
    /**
138
     * Boot all providers.
139
     *
140
     * @return void
141
     */
142 View Code Duplication
    protected function bootEach() {
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
143
        foreach ($this->providers as $class => &$data) {
144
            if ( ! array_contains(array_get($data, 'tags'), ProviderTag::BOOTED)) {
145
                $this->initialize();
146
147
                array_add($data, 'tags', ProviderTag::BOOTED);
148
                $instance = array_get($data, 'instance');
149
150
                if (method_exists($instance, 'boot')) {
151
                    $this->getProviderInvoker()
152
                        ->boot($instance, $this->getSharedArguments());
153
                }
154
155
                $this->bootEach();
156
                break;
157
            }
158
        }
159
    }
160
161
    /**
162
     * Shutdown all providers.
163
     *
164
     * @return void
165
     */
166
    public function shutdown() {
167
        $this->shutdownEach();
168
169
        foreach ($this->providers as $class => &$data) {
170
            $data['tags'] = [];
171
        }
172
    }
173
174
    /**
175
     * Shutdown all providers.
176
     */
177 View Code Duplication
    protected function shutdownEach() {
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
178
        foreach ($this->providers as $class => &$data) {
179
            if ( ! array_contains(array_get($data, 'tags'), ProviderTag::SHUTDOWN)) {
180
                $this->boot();
181
182
                array_add($data, 'tags', ProviderTag::SHUTDOWN);
183
                $instance = array_get($data, 'instance');
184
185
                if (method_exists($instance, 'shutdown')) {
186
                    $this->getProviderInvoker()
187
                        ->boot($instance, $this->getSharedArguments());
188
                }
189
190
                $this->shutdownEach();
191
                break;
192
            }
193
        }
194
    }
195
196
    /**
197
     * @param string $provider
198
     *
199
     * @throws InvalidProviderException
200
     */
201
    public function addProvider($provider) {
202
        $this->validateProvider($provider);
203
204
        if (is_object($provider)) {
205
            $class = get_class($provider);
206
            $instance = $provider;
207
        } else {
208
            $class = $provider;
209
            $instance = null;
210
        }
211
212
        if ( ! array_has($this->providers, $class)) {
213
            $this->providers[$class] = [
214
                'instance' => $instance,
215
                'tags' => [],
216
            ];
217
        }
218
    }
219
220
    /**
221
     * @param array $providers
222
     */
223
    public function addProviders(array $providers) {
224
        foreach ($providers as $provider) {
225
            $this->addProvider($provider);
226
        }
227
    }
228
229
    /**
230
     * @return array
231
     */
232
    public function getProviders() {
233
        return $this->providers;
234
    }
235
236
    /**
237
     * @return IDictionary
238
     */
239
    public function getSharedArguments() {
240
        return $this->sharedArguments;
241
    }
242
243
    /**
244
     * @param IDictionary $shared
245
     */
246
    public function setSharedArguments(IDictionary $shared) {
247
        $this->sharedArguments = $shared;
248
    }
249
250
    /**
251
     * @return IProviderInvoker
252
     */
253
    public function getProviderInvoker() {
254
        return $this->providerInvoker;
255
    }
256
257
    /**
258
     * @param IProviderInvoker $invoker
259
     */
260
    public function setProviderInvoker(IProviderInvoker $invoker) {
261
        $this->providerInvoker = $invoker;
262
    }
263
264
    /**
265
     * @param $provider
266
     *
267
     * @throws InvalidProviderException
268
     */
269
    protected function validateProvider($provider) {
270
        if (is_string($provider)) {
271
            if ( ! class_exists($provider)) {
272
                $message = s('Provider class %s does not exist.', $provider);
273
274
                throw new InvalidProviderException($message);
275
            }
276
        } else if ( ! is_object($provider)) {
277
            $message = s(
278
                'Provider must be either a valid class name, or an instance, received: "%s".',
279
                get_type($provider)
280
            );
281
282
            throw new InvalidProviderException($message);
283
        }
284
    }
285
286
    /**
287
     * @return IProviderInvoker
288
     */
289
    protected function createProviderInvoker() {
290
        return new ProviderInvoker();
291
    }
292
293
    /**
294
     * @return Dictionary
295
     */
296
    protected function createSharedArguments() {
297
        return new Dictionary();
298
    }
299
}
300