|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Scabbia2 Helpers Component |
|
4
|
|
|
* https://github.com/eserozvataf/scabbia2 |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
* |
|
9
|
|
|
* @link https://github.com/eserozvataf/scabbia2-helpers for the canonical source repository |
|
10
|
|
|
* @copyright 2010-2016 Eser Ozvataf. (http://eser.ozvataf.com/) |
|
11
|
|
|
* @license http://www.apache.org/licenses/LICENSE-2.0 - Apache License, Version 2.0 |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Scabbia\Helpers; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* A bunch of utility methods for runtime hacks |
|
18
|
|
|
* |
|
19
|
|
|
* @package Scabbia\Helpers |
|
20
|
|
|
* @author Eser Ozvataf <[email protected]> |
|
21
|
|
|
* @since 2.0.0 |
|
22
|
|
|
* |
|
23
|
|
|
* @scabbia-compile |
|
24
|
|
|
*/ |
|
25
|
|
|
class Runtime |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* Default variables for runtime hacks |
|
29
|
|
|
* |
|
30
|
|
|
* @type array $defaults array of default variables |
|
31
|
|
|
*/ |
|
32
|
|
|
public static $defaults = [ |
|
33
|
|
|
]; |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Constructor to prevent new instances of Runtime class |
|
38
|
|
|
* |
|
39
|
|
|
* @return Runtime |
|
|
|
|
|
|
40
|
|
|
*/ |
|
41
|
|
|
final private function __construct() |
|
42
|
|
|
{ |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Clone method to prevent duplication of Runtime class |
|
47
|
|
|
* |
|
48
|
|
|
* @return Runtime |
|
49
|
|
|
*/ |
|
50
|
|
|
final private function __clone() |
|
51
|
|
|
{ |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Unserialization method to prevent restoration of Runtime class |
|
56
|
|
|
* |
|
57
|
|
|
* @return Runtime |
|
58
|
|
|
*/ |
|
59
|
|
|
final private function __wakeup() |
|
60
|
|
|
{ |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Sets the default variables |
|
65
|
|
|
* |
|
66
|
|
|
* @param array $uDefaults variables to be set |
|
67
|
|
|
* |
|
68
|
|
|
* @return void |
|
69
|
|
|
*/ |
|
70
|
|
|
public static function setDefaults($uDefaults) |
|
71
|
|
|
{ |
|
72
|
|
|
self::$defaults = $uDefaults + self::$defaults; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Allows on-the-fly construction of classes |
|
77
|
|
|
* |
|
78
|
|
|
* @param mixed $uCallback callback |
|
79
|
|
|
* |
|
80
|
|
|
* @return mixed callback |
|
81
|
|
|
*/ |
|
82
|
|
|
public static function callbacks($uCallback) |
|
83
|
|
|
{ |
|
84
|
|
|
if (is_string($uCallback) && ($tPos = strrpos($uCallback, "@")) !== false) { |
|
85
|
|
|
$tClassName = substr($uCallback, 0, $tPos); |
|
86
|
|
|
$uCallback = [new $tClassName (), substr($uCallback, $tPos + 1)]; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
return $uCallback; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.