Issues (30)

includes/events/system.php (3 issues)

1
<?php
2
3
/**
4
 * This file can be used to provide listeners for system events (events provided by VELOX classes).
5
 *
6
 * Note that you can in theory register listeners for these events anywhere in the project, but it's recommended to
7
 * register them here to prepare listeners/bindings before the events are dispatched/triggered.
8
 *
9
 * You can freely add additional files in the '/includes/events/' directory. VELOX will load it for you.
10
 */
11
12
13
14
// Examples
15
// --------
16
// * Check out "/storage/logs/events.log" to see the result.
17
18
Event::listen(\MAKS\Velox\App::ON_SHUTDOWN, function () {
0 ignored issues
show
The method listen() does not exist on Event. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

18
Event::/** @scrutinizer ignore-call */ 
19
       listen(\MAKS\Velox\App::ON_SHUTDOWN, function () {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
19
    App::log('App has shutdown at "{date}" and took "{time}" to process the request', [
20
        'date' => (new DateTime('now'))->format('Y-m-d H:i:s'),
21
        'time' => sprintf('%.2fms', (microtime(true) - START_TIME) * 1000),
22
    ], 'events');
23
});
24
25
Event::listen(\MAKS\Velox\Backend\Auth::ON_REGISTER, function ($user) {
26
    App::log('A new user with username "{username}" has registered', [
27
        'username' => $user->getUsername()
28
    ], 'events');
29
});
30
31
Event::listen(\MAKS\Velox\Backend\Config::ON_LOAD, function (&$config) {
32
    App::log('The config was loaded', null, 'events');
33
34
    Config::set('eventExecuted', true);
35
    if ($config['eventExecuted']) {
36
        App::log('The config was manipulated', null, 'events');
37
    }
38
});
39
40
Event::listen(\MAKS\Velox\Backend\Controller::ON_CONSTRUCT, function () {
41
    /** @var \MAKS\Velox\Backend\Controller $this */
42
    $this->vars['__uid'] = uniqid();
0 ignored issues
show
The property vars is declared protected in MAKS\Velox\Backend\Controller and cannot be accessed from this context.
Loading history...
Comprehensibility Best Practice introduced by
The variable $this seems to be never defined.
Loading history...
43
44
    App::log('The "{class}" has been constructed', ['class' => get_class($this)], 'events');
45
});
46
47
Event::listen(\MAKS\Velox\Backend\Router::ON_REGISTER_HANDLER, function (&$route) {
48
    App::log('The handler for the route "{route}" has been registered', ['route' => $route['expression']], 'events');
49
});
50
51
Event::listen(\MAKS\Velox\Frontend\Data::ON_LOAD, function (&$data) {
52
    App::log('The data was loaded', null, 'events');
53
54
    Data::set('eventExecuted', true);
55
    if ($data['eventExecuted']) {
56
        App::log('The data was manipulated', null, 'events');
57
    }
58
});
59
60
Event::listen(\MAKS\Velox\Frontend\View::BEFORE_RENDER, function (&$variables) {
61
    $variables['__uid'] = uniqid();
62
    App::log('The UID "{uid}" was added to the view as "$__uid"', ['uid' => $variables['__uid']], 'events');
63
});
64
65
66
67
// Available events
68
// ----------------
69
// * App::ON_TERMINATE
70
// * App::ON_SHUTDOWN
71
// * Auth::ON_REGISTER
72
// * Auth::AFTER_REGISTER
73
// * Auth::ON_UNREGISTER
74
// * Auth::ON_LOGIN
75
// * Auth::ON_LOGOUT
76
// * Config::ON_LOAD
77
// * Config::ON_CACHE
78
// * Config::ON_CLEAR_CACHE
79
// * Controller::ON_CONSTRUCT
80
// * Router::ON_REGISTER_HANDLER
81
// * Router::ON_REGISTER_MIDDLEWARE
82
// * Router::ON_START
83
// * Router::BEFORE_REDIRECT
84
// * Router::BEFORE_FORWARD
85
// * Data::ON_LOAD
86
// * View::BEFORE_RENDER
87
// * View::ON_CACHE
88
// * View::ON_CACHE_CLEAR
89