1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Jitamin. |
5
|
|
|
* |
6
|
|
|
* Copyright (C) Jitamin Team |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Jitamin\Foundation\Plugin; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Plugin Base class. |
16
|
|
|
*/ |
17
|
|
|
abstract class Base extends \Jitamin\Foundation\Base |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Method called for each request. |
21
|
|
|
* |
22
|
|
|
* @abstract |
23
|
|
|
*/ |
24
|
|
|
abstract public function initialize(); |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Override default CSP rules. |
28
|
|
|
* |
29
|
|
|
* @param array $rules |
30
|
|
|
*/ |
31
|
|
|
public function setContentSecurityPolicy(array $rules) |
32
|
|
|
{ |
33
|
|
|
$this->container['cspRules'] = $rules; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Returns all classes that needs to be stored in the DI container. |
38
|
|
|
* |
39
|
|
|
* @return array |
40
|
|
|
*/ |
41
|
|
|
public function getClasses() |
42
|
|
|
{ |
43
|
|
|
return []; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Returns all helper classes that needs to be stored in the DI container. |
48
|
|
|
* |
49
|
|
|
* @return array |
50
|
|
|
*/ |
51
|
|
|
public function getHelpers() |
52
|
|
|
{ |
53
|
|
|
return []; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Listen on internal events. |
58
|
|
|
* |
59
|
|
|
* @param string $event |
60
|
|
|
* @param callable $callback |
61
|
|
|
*/ |
62
|
|
|
public function on($event, $callback) |
63
|
|
|
{ |
64
|
|
|
$container = $this->container; |
65
|
|
|
|
66
|
|
|
$this->dispatcher->addListener($event, function () use ($container, $callback) { |
|
|
|
|
67
|
|
|
call_user_func($callback, $container); |
68
|
|
|
}); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Get plugin name. |
73
|
|
|
* |
74
|
|
|
* This method should be overridden by your Plugin class |
75
|
|
|
* |
76
|
|
|
* @return string |
77
|
|
|
*/ |
78
|
|
|
public function getPluginName() |
79
|
|
|
{ |
80
|
|
|
return ucfirst(substr(get_called_class(), 15, -7)); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Get plugin description. |
85
|
|
|
* |
86
|
|
|
* This method should be overridden by your Plugin class |
87
|
|
|
* |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
|
|
public function getPluginDescription() |
91
|
|
|
{ |
92
|
|
|
return ''; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Get plugin author. |
97
|
|
|
* |
98
|
|
|
* This method should be overridden by your Plugin class |
99
|
|
|
* |
100
|
|
|
* @return string |
101
|
|
|
*/ |
102
|
|
|
public function getPluginAuthor() |
103
|
|
|
{ |
104
|
|
|
return '?'; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Get plugin version. |
109
|
|
|
* |
110
|
|
|
* This method should be overridden by your Plugin class |
111
|
|
|
* |
112
|
|
|
* @return string |
113
|
|
|
*/ |
114
|
|
|
public function getPluginVersion() |
115
|
|
|
{ |
116
|
|
|
return '?'; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Get plugin homepage. |
121
|
|
|
* |
122
|
|
|
* This method should be overridden by your Plugin class |
123
|
|
|
* |
124
|
|
|
* @return string |
125
|
|
|
*/ |
126
|
|
|
public function getPluginHomepage() |
127
|
|
|
{ |
128
|
|
|
return ''; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.