1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Platine Template |
5
|
|
|
* |
6
|
|
|
* Platine Template is a template engine that has taken a lot of inspiration from Django. |
7
|
|
|
* |
8
|
|
|
* This content is released under the MIT License (MIT) |
9
|
|
|
* |
10
|
|
|
* Copyright (c) 2020 Platine Template |
11
|
|
|
* Copyright (c) 2014 Guz Alexander, http://guzalexander.com |
12
|
|
|
* Copyright (c) 2011, 2012 Harald Hanek, http://www.delacap.com |
13
|
|
|
* Copyright (c) 2006 Mateo Murphy |
14
|
|
|
* |
15
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
16
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
17
|
|
|
* in the Software without restriction, including without limitation the rights |
18
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
19
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
20
|
|
|
* furnished to do so, subject to the following conditions: |
21
|
|
|
* |
22
|
|
|
* The above copyright notice and this permission notice shall be included in all |
23
|
|
|
* copies or substantial portions of the Software. |
24
|
|
|
* |
25
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
26
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
27
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
28
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
29
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
30
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
31
|
|
|
* SOFTWARE. |
32
|
|
|
*/ |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @file Drop.php |
36
|
|
|
* |
37
|
|
|
* The Template Drop class |
38
|
|
|
* |
39
|
|
|
* @package Platine\Template\Parser |
40
|
|
|
* @author Platine Developers Team |
41
|
|
|
* @copyright Copyright (c) 2020 |
42
|
|
|
* @license http://opensource.org/licenses/MIT MIT License |
43
|
|
|
* @link http://www.iacademy.cf |
44
|
|
|
* @version 1.0.0 |
45
|
|
|
* @filesource |
46
|
|
|
*/ |
47
|
|
|
|
48
|
|
|
declare(strict_types=1); |
49
|
|
|
|
50
|
|
|
namespace Platine\Template\Parser; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Class Drop |
54
|
|
|
* @package Platine\Template\Parser |
55
|
|
|
* |
56
|
|
|
*/ |
57
|
|
|
/** |
58
|
|
|
* A drop is a class which allows you to to export DOM like things to template. |
59
|
|
|
* Methods of drops are callable. |
60
|
|
|
* The main use for drops is the implement lazy loaded objects. |
61
|
|
|
* If you would like to make data available to the web designers which you don't |
62
|
|
|
* want loaded unless needed then a drop is a great way to do that. |
63
|
|
|
*/ |
64
|
|
|
abstract class Drop |
65
|
|
|
{ |
66
|
|
|
/** |
67
|
|
|
* The context instance to use |
68
|
|
|
* @var Context |
69
|
|
|
*/ |
70
|
|
|
protected Context $context; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Set the context instance for future use |
74
|
|
|
* @param Context $context |
75
|
|
|
* @return $this |
76
|
|
|
*/ |
77
|
|
|
public function setContext(Context $context): self |
78
|
|
|
{ |
79
|
|
|
$this->context = $context; |
80
|
|
|
|
81
|
|
|
return $this; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Returns true if the drop supports the given method |
86
|
|
|
* @param string $key |
87
|
|
|
* @return bool |
88
|
|
|
*/ |
89
|
|
|
public function hasKey(string $key): bool |
90
|
|
|
{ |
91
|
|
|
return true; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Invoke a specific method |
96
|
|
|
* @param string $method |
97
|
|
|
* @return mixed |
98
|
|
|
*/ |
99
|
|
|
public function invokeDrop(string $method) |
100
|
|
|
{ |
101
|
|
|
$result = $this->beforeMethod($method); |
|
|
|
|
102
|
|
|
if ($result === null && is_callable([$this, $method])) { |
103
|
|
|
$result = $this->{$method}(); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return $result; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Return the current instance |
111
|
|
|
* @return $this |
112
|
|
|
*/ |
113
|
|
|
public function toObject(): self |
114
|
|
|
{ |
115
|
|
|
return $this; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* The string representation of this class |
120
|
|
|
* @return string |
121
|
|
|
*/ |
122
|
|
|
public function __toString(): string |
123
|
|
|
{ |
124
|
|
|
return get_class($this); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Catch all method that is invoked before a specific method |
129
|
|
|
* @param string $method |
130
|
|
|
* @return mixed |
131
|
|
|
*/ |
132
|
|
|
protected function beforeMethod(string $method) |
133
|
|
|
{ |
134
|
|
|
return null; |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.