Passed
Push — 0.7.0 ( 723ad3...071b71 )
by Alexander
03:46 queued 11s
created

EventServiceProvider::loadEventPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php 
2
3
/**
4
 * Lenevor Framework
5
 *
6
 * LICENSE
7
 *
8
 * This source file is subject to the new BSD license that is bundled
9
 * with this package in the file license.md.
10
 * It is also available through the world-wide-web at this URL:
11
 * https://lenevor.com/license
12
 * If you did not receive a copy of the license and are unable to
13
 * obtain it through the world-wide-web, please send an email
14
 * to [email protected] so we can send you a copy immediately.
15
 *
16
 * @package     Lenevor
17
 * @subpackage  Base
18
 * @link        https://lenevor.com
19
 * @copyright   Copyright (c) 2019 - 2021 Alexander Campo <[email protected]>
20
 * @license     https://opensource.org/licenses/BSD-3-Clause New BSD license or see https://lenevor.com/license or see /license.md
21
 */
22
23
namespace Syscodes\Core\Support\Providers;
24
25
use Syscodes\Support\Facades\Event;
26
use Syscodes\Support\ServiceProvider;
27
28
/**
29
 * Manage all events occurred in the application.
30
 *  
31
 * @author Alexander Campo <[email protected]>
32
 */
33
class EventServiceProvider extends ServiceProvider
34
{
35
    /**
36
     * The event handler mappings for the application.
37
     * 
38
     * @var array $listen
39
     */
40
    protected $listen = [];
41
42
    /**
43
     * The subscriber classes to register.
44
     * 
45
     * @var array $suscribe
46
     */
47
    protected $subscribe = [];
48
49
    /**
50
     * Register any application services.
51
     * 
52
     * @return void
53
     */
54
    public function register()
55
    {
56
        $this->booting(function () {
57
            $events = $this->listens();
58
59
            foreach ((array) $events as $event => $listeners) {
60
                foreach ($listeners as $listener) {
61
                    Event::listen($event, $listener);
62
                }
63
            }
64
            
65
            foreach ($this->subscribe as $subscriber) {
66
                Event::subscribe($subscriber);
67
            }
68
        });
69
    }
70
71
    /**
72
     * Get the events and handlers.
73
     * 
74
     * @return array
75
     */
76
    public function listens()
77
    {
78
        return $this->listen;
79
    }
80
}