1 | <?php |
||
12 | class Singleton |
||
13 | { |
||
14 | use SingletonTrait; |
||
15 | /** |
||
16 | * @var bool Flag that indicated if the class is already loaded |
||
17 | */ |
||
18 | protected $loaded = false; |
||
19 | |||
20 | 2 | public function __construct() |
|
25 | |||
26 | /** |
||
27 | * Magic setter |
||
28 | * @param $variable |
||
29 | * @param $value |
||
30 | */ |
||
31 | 7 | public function __set($variable, $value) |
|
32 | { |
||
33 | 7 | if (property_exists(get_class($this), $variable)) { |
|
34 | 7 | $this->$variable = $value; |
|
35 | } |
||
36 | 7 | } |
|
37 | |||
38 | /** |
||
39 | * Magic getter |
||
40 | * @param string $variable |
||
41 | * @return $mixed |
||
42 | */ |
||
43 | 1 | public function __get($variable) |
|
47 | |||
48 | /** |
||
49 | * Método que devuelve si una clase está isntanciada correctamente |
||
50 | * @return bool |
||
51 | */ |
||
52 | 2 | public function isLoaded() |
|
56 | |||
57 | /** |
||
58 | * Método que configura como cargada una clase |
||
59 | * @param bool $loaded |
||
60 | */ |
||
61 | 2 | public function setLoaded($loaded = true) |
|
65 | |||
66 | /** |
||
67 | * HELPERS |
||
68 | */ |
||
69 | |||
70 | /** |
||
71 | * Método que extrae el nombre de la clase |
||
72 | * @return string |
||
73 | */ |
||
74 | 1 | public function getShortName() |
|
79 | |||
80 | /** |
||
81 | * Dependency injector service invoker |
||
82 | * @param string $variable |
||
83 | * @param bool $singleton |
||
84 | * @param string $classNameSpace |
||
85 | * @return $this |
||
86 | */ |
||
87 | 2 | public function load($variable, $singleton = true, $classNameSpace = null) |
|
88 | { |
||
89 | 2 | $calledClass = get_called_class(); |
|
90 | try { |
||
91 | 2 | $instance = InjectorHelper::constructInyectableInstance($variable, $singleton, $classNameSpace, $calledClass); |
|
92 | 2 | $setter = "set" . ucfirst($variable); |
|
93 | 2 | if (method_exists($calledClass, $setter)) { |
|
94 | 1 | $this->$setter($instance); |
|
95 | } else { |
||
96 | 2 | $this->$variable = $instance; |
|
97 | } |
||
98 | } catch (\Exception $e) { |
||
99 | Logger::log($e->getMessage() . ': ' . $e->getFile() . ' [' . $e->getLine() . ']', LOG_ERR); |
||
100 | } |
||
101 | 2 | return $this; |
|
102 | } |
||
103 | |||
104 | /** |
||
105 | * Método que inyecta automáticamente las dependencias en la clase |
||
106 | */ |
||
107 | 2 | public function init() |
|
131 | } |
||
132 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.