Passed
Push — master ( b817d9...04ae87 )
by 世昌
02:23
created

Event::call()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 13
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 17
rs 9.8333
1
<?php
2
3
4
namespace suda\application;
5
6
use suda\framework\runnable\Runnable;
7
8
class Event extends \suda\framework\Event
9
{
10
    /**
11
     * @var Application
12
     */
13
    protected $application;
14
15
    /**
16
     * Event constructor.
17
     * @param Application $application
18
     */
19
    public function __construct(Application $application)
20
    {
21
        $this->application = $application;
22
    }
23
24
    /**
25
     * @param string $event
26
     * @param mixed $command
27
     * @param array $args
28
     * @return mixed
29
     */
30
    protected function call(string $event, $command, array &$args)
31
    {
32
        $runnable = new Runnable($command);
33
        $this->application->debug()->debug('invoke {event} event run {runnable}', [
34
            'runnable' => $runnable->getName(),
35
            'event' => $event
36
        ]);
37
        try {
38
            return $runnable->apply($args);
39
        } catch (\Throwable $e) {
40
            $this->application->debug()->error('invoke {event} event run {runnable} error', [
41
                'runnable' => $runnable->getName(),
42
                'event' => $event
43
            ]);
44
            $this->application->debug()->uncaughtException($e);
45
            $this->application->dumpException($e);
46
            return null;
47
        }
48
    }
49
}
50