Passed
Push — master ( 0d9fd2...086231 )
by Oleg
03:35
created

Micro::getContainerClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 2
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php /** Micro */
2
3
namespace Micro;
4
5
use Micro\Base\Dispatcher;
6
use Micro\Base\Exception;
7
use Micro\Base\FatalError;
8
use Micro\Base\IContainer;
9
use Micro\Base\IDispatcher;
10
use Micro\Base\IInjector;
11
use Micro\Cli\Console;
12
use Micro\Cli\Consoles\DefaultConsoleCommand;
13
use Micro\Mvc\Controllers\IController;
14
use Micro\Resolver\IResolver;
15
use Micro\Web\IOutput;
16
use Micro\Web\IRequest;
17
use Micro\Web\IResponse;
18
use Micro\Web\Response;
19
20
/**
21
 * Micro class file.
22
 *
23
 * Base class for initialize MicroPHP, used as bootstrap framework.
24
 *
25
 * @author Oleg Lunegov <[email protected]>
26
 * @link https://github.com/lugnsk/micro
27
 * @copyright Copyright &copy; 2013 Oleg Lunegov
28
 * @license /LICENSE
29
 * @package micro
30
 * @version 1.0
31
 * @since 1.0
32
 */
33
class Micro
34
{
35
    /** @const string VERSION Version framework */
36
    const VERSION = '1.1';
37
38
    /** @var IContainer $container Container is a container for components and options */
39
    protected $container;
40
    /** @var string $appDir */
41
    protected $appDir;
42
    /** @var string $webDir */
43
    protected $webDir;
44
45
    /** @var bool $loaded Micro loaded flag */
46
    private $loaded;
47
    /** @var bool $debug Debug-mode flag */
48
    private $debug = true;
49
    /** @var string $environment Application environment */
50
    private $environment = 'devel';
51
    /** @var float $startTime Time of start framework */
52
    private $startTime;
53
54
55
    /**
56
     * Initialize application
57
     *
58
     * @access public
59
     *
60
     * @param string $environment Application environment: devel , production , test, other
61
     * @param bool $debug Debug-mode flag
62
     *
63
     * @result void
64
     */
65
    public function __construct($environment = 'devel', $debug = true)
66
    {
67
        $this->webDir = getenv('DOCUMENT_ROOT');
68
        $this->environment = (string)$environment;
69
        $this->debug = (bool)$debug;
70
        $this->loaded = false;
71
72
        ini_set('display_errors', (integer)$this->debug);
73
        ini_set('log_errors', (integer)$this->debug);
74
75
        FatalError::register();
76
77
        if ($this->debug) {
78
            ini_set('error_reporting', -1);
79
            $this->startTime = microtime(true);
80
        }
81
    }
82
83
    /**
84
     * Clone application
85
     *
86
     * @access public
87
     *
88
     * @return void
89
     */
90
    public function __clone()
91
    {
92
        if ($this->debug) { // start new timer
93
            $this->startTime = microtime(true);
94
        }
95
96
        $this->loaded = false; // deactivate loaded
97
        $this->container = null; // remove configured container
98
    }
99
100
    /**
101
     * Running application
102
     *
103
     * @access public
104
     *
105
     * @param IRequest $request Request object
106
     *
107
     * @return \Micro\Web\IOutput|\Micro\Web\IResponse
108
     * @throws \Exception
109
     * @throws \Micro\Base\Exception
110
     */
111
    public function run(IRequest $request)
112
    {
113
        try {
114
            return $this->doRun($request);
115
        } catch (\Exception $e) {
116 View Code Duplication
            if ($this->debug) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
117
                if (($dispatcher = $this->container->dispatcher) && $dispatcher instanceof IDispatcher) {
0 ignored issues
show
Bug introduced by
Accessing dispatcher on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
118
                    $dispatcher->signal('kernel.exception', ['exception' => $e]);
119
                }
120
121
                throw $e;
122
            }
123
124
            return $this->doException($e);
125
        }
126
    }
127
128
    /**
129
     * Starting ...
130
     *
131
     * @access private
132
     *
133
     * @param IRequest $request
134
     *
135
     * @return \Micro\Web\IResponse|\Micro\Web\IOutput
136
     * @throws \Micro\Base\Exception
137
     */
138
    private function doRun(IRequest $request)
139
    {
140
        if (!$this->loaded) {
141
            $this->initializeContainer();
142
143
            $this->addListener('kernel.kill', function(array $params) {
144
                if (
145
                    $params['container']->kernel->isDebug() &&
146
                    !$params['container']->request->isCli() &&
147
                    !$params['container']->request->isAjax()
148
                ) {
149
                    // Add timer into page
150
                    echo '<div class=debug_timer>', (microtime(true) - $params['container']->kernel->getStartTime()), '</div>';
151
                }
152
153
                if (false === $params['container']->kernel->loaded) {
154
                    return;
155
                }
156
157
                $params['container']->kernel->container = null;
158
                $params['container']->kernel->loaded = false;
159
            });
160
        }
161
162
        $this->container->request = $request;
0 ignored issues
show
Bug introduced by
Accessing request on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
163
        if (($output = $this->sendSignal('kernel.request', ['container' => $this->container])) instanceof IResponse) {
164
            return $output;
165
        }
166
167
        /** @var IResolver $resolver */
168
        $resolver = $this->getResolver();
169
        if (($output = $this->sendSignal('kernel.router', ['resolver' => $resolver])) instanceof IResponse) {
170
            return $output;
171
        }
172
173
        /** @var IController|Console $app */
174
        $app = $resolver->getApplication();
175
        if (($output = $this->sendSignal('kernel.controller', ['application' => $app])) instanceof IResponse) {
176
            return $output;
177
        }
178
179
        $output = $app->action((string)$resolver->getAction());
180
        if (!$output instanceof IOutput) {
181
            $response = $this->container->response ?: new Response;
0 ignored issues
show
Bug introduced by
Accessing response on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
182
            $response->setBody((string)$output);
183
            $output = $response;
184
        }
185
186
        $this->sendSignal('kernel.response', ['output' => $output]);
187
188
        return $output;
189
    }
190
191
    /**
192
     * Initialization container
193
     *
194
     * @access protected
195
     * @return void
196
     */
197
    protected function initializeContainer()
198
    {
199
        $class = $this->getInjectorClass();
200
        if (!$class || !class_exists($class)) {
201
            $class = '\Micro\Base\Injector';
202
        }
203
204
        /** @var IInjector $inject */
205
        $inject = new $class($this->getConfig());
206
        $inject->addRequirement('kernel', $this);
207
208
        if (!$inject->check('dispatcher') || !($inject->get('dispatcher') instanceof IDispatcher)) {
209
            $inject->addRequirement('dispatcher', new Dispatcher);
210
        }
211
212
        /** @var IDispatcher $dispatcher */
213
        $dispatcher = $inject->get('dispatcher');
214
        $dispatcher->signal('kernel.boot', ['injector' => $inject]);
215
216
        $this->loaded = true;
217
    }
218
219
    /**
220
     * Get full class name
221
     * @return string
222
     */
223
    protected function getInjectorClass()
224
    {
225
        return '';
226
    }
227
228
    /**
229
     * Default config path
230
     *
231
     * @return string
232
     */
233
    protected function getConfig()
234
    {
235
        return $this->getAppDir().'/configs/index.php';
236
    }
237
238
    /**
239
     * Get application directory
240
     *
241
     * @return string
242
     */
243
    public function getAppDir()
244
    {
245
        if (!$this->appDir) {
246
            $this->appDir = realpath(dirname((new \ReflectionObject($this))->getFileName()));
247
        }
248
249
        return $this->appDir;
250
    }
251
252
    /**
253
     * Add listener on event
254
     *
255
     * @access public
256
     *
257
     * @param string $listener listener name
258
     * @param \Closure $event ['Object', 'method'] or callable
259
     * @param int|null $prior priority
260
     *
261
     * @return bool
262
     */
263
    protected function addListener($listener, $event, $prior = null)
264
    {
265
        if (!is_string($listener) || !$this->container) {
266
            return false;
267
        }
268
269
        if (($dispatcher = $this->container->dispatcher) && $dispatcher instanceof IDispatcher) {
0 ignored issues
show
Bug introduced by
Accessing dispatcher on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
270
            return $dispatcher->addListener($listener, $event, $prior);
271
        }
272
273
        return null;
274
    }
275
276
    /**
277
     * Send signal to dispatcher
278
     *
279
     * @param string $signal
280
     * @param $params
281
     * @return mixed
282
     */
283
    protected function sendSignal($signal, $params)
284
    {
285
        if (($dispatcher = $this->container->dispatcher) && $dispatcher instanceof IDispatcher) {
0 ignored issues
show
Bug introduced by
Accessing dispatcher on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
286
            return $dispatcher->signal($signal, $params);
287
        }
288
289
        return null;
290
    }
291
292
    /**
293
     * Get resolver
294
     *
295
     * @access protected
296
     *
297
     * @return IResolver
298
     * @throws \Micro\Base\Exception
299
     */
300
    protected function getResolver()
301
    {
302
        if ($this->container->request->isCli()) {
0 ignored issues
show
Bug introduced by
Accessing request on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
303
            $resolver = $this->container->consoleResolver ?: '\Micro\Resolver\ConsoleResolver';
0 ignored issues
show
Bug introduced by
Accessing consoleResolver on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
304
        } else {
305
            $resolver = $this->container->resolver ?: '\Micro\Resolver\HMVCResolver';
0 ignored issues
show
Bug introduced by
Accessing resolver on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
306
        }
307
308
        if (is_string($resolver) && is_subclass_of($resolver, '\Micro\Resolver\IResolver')) {
309
            $resolver = new $resolver($this->container);
310
        }
311
312
        if (!$resolver instanceof IResolver) {
313
            throw new Exception('Resolver is not implement an IResolver');
314
        }
315
316
        return $resolver;
317
    }
318
319
    /**
320
     * Do exception
321
     *
322
     * @access private
323
     *
324
     * @param \Exception $e Exception
325
     *
326
     * @return \Micro\Web\IOutput|\Micro\Web\IResponse
327
     * @throws \Micro\Base\Exception
328
     */
329
    private function doException(\Exception $e)
330
    {
331
        $output = $this->container->request->isCli() ? new DefaultConsoleCommand([]) : new Response();
0 ignored issues
show
Bug introduced by
Accessing request on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
332
333
        if ($this->container->request->isCli()) {
0 ignored issues
show
Bug introduced by
Accessing request on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
334
            $output->data = '"Error #'.$e->getCode().' - '.$e->getMessage().'"';
335
            $output->execute();
0 ignored issues
show
Bug introduced by
The method execute does only exist in Micro\Cli\Consoles\DefaultConsoleCommand, but not in Micro\Web\Response.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
336
337
            return $output;
338
        }
339
        if (!$this->container->errorController || !$this->container->errorAction) {
0 ignored issues
show
Bug introduced by
Accessing errorController on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
Bug introduced by
Accessing errorAction on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
340
            $output->setBody('Option `errorController` or `errorAction` not configured');
0 ignored issues
show
Bug introduced by
The method setBody does only exist in Micro\Web\Response, but not in Micro\Cli\Consoles\DefaultConsoleCommand.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
341
342
            return $output;
343
        }
344
345
        if (($request = $this->container->request) && $request instanceof IRequest) {
0 ignored issues
show
Bug introduced by
Accessing request on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
346
            $request->setPost('error', $e);
347
        }
348
349
        $controller = $this->container->errorController;
0 ignored issues
show
Bug introduced by
Accessing errorController on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
350
351
        /** @var \Micro\mvc\controllers\IController $result */
352
        $result = new $controller($this->container, false);
353
        $result = $result->action($this->container->errorAction);
0 ignored issues
show
Bug introduced by
Accessing errorAction on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
354
        if ($result instanceof IOutput) {
355
            return $result;
356
        }
357
358
        $output->setBody((string)$result);
359
360
        return $output;
361
    }
362
363
    /**
364
     * Get web root directory
365
     *
366
     * @return string
367
     */
368
    public function getWebDir()
369
    {
370
        return $this->webDir;
371
    }
372
373
    /**
374
     * Get start time
375
     *
376
     * @access public
377
     *
378
     * @return double
379
     */
380
    public function getStartTime()
381
    {
382
        return $this->startTime;
383
    }
384
385
    /**
386
     * Terminate application
387
     *
388
     * @access public
389
     *
390
     * @return void
391
     */
392
    public function terminate()
393
    {
394 View Code Duplication
        if (($dispatcher = $this->container->dispatcher) && $dispatcher instanceof IDispatcher) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
Bug introduced by
Accessing dispatcher on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
395
            $dispatcher->signal('kernel.kill', ['container' => $this->container]);
396
        }
397
    }
398
399
    /**
400
     * Get status of debug
401
     *
402
     * @access public
403
     *
404
     * @return bool
405
     */
406
    public function isDebug()
407
    {
408
        return $this->debug;
409
    }
410
411
    /**
412
     * Get components container
413
     *
414
     * @access public
415
     *
416
     * @return IContainer
417
     */
418
    public function getContainer()
419
    {
420
        return $this->container;
421
    }
422
423
    /**
424
     * Get character set
425
     *
426
     * @access public
427
     *
428
     * @return string
429
     */
430
    public function getCharset()
431
    {
432
        return 'UTF-8';
433
    }
434
435
    /**
436
     * Get logs directory
437
     *
438
     * @return string
439
     */
440
    public function getLogDir()
441
    {
442
        return $this->getAppDir().'/logs';
443
    }
444
445
    /**
446
     * Get cache directory
447
     *
448
     * @return string
449
     */
450
    public function getCacheDir()
451
    {
452
        return $this->getAppDir().'/cache/'.$this->getEnvironment();
453
    }
454
455
    /**
456
     * Get environment name
457
     *
458
     * @access public
459
     *
460
     * @return string
461
     */
462
    public function getEnvironment()
463
    {
464
        return $this->environment;
465
    }
466
}
467