|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by Gorlum 08.01.2018 15:16 |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Common\Traits; |
|
7
|
|
|
|
|
8
|
|
|
use Common\Interfaces\IContainer; |
|
9
|
|
|
|
|
10
|
|
|
trait TContainer { |
|
11
|
|
|
/** |
|
12
|
|
|
* @return ?IContainer |
|
13
|
|
|
*/ |
|
14
|
|
|
public function _getContainer() { |
|
15
|
|
|
return null; |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
public function __set($name, $value) { |
|
19
|
|
|
if (is_object($this->_getContainer())) { |
|
|
|
|
|
|
20
|
|
|
$this->_getContainer()->__set($this->_containerTranslatePropertyName($name), $value); |
|
21
|
|
|
} |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function __isset($name) { |
|
25
|
|
|
return is_object($this->_getContainer()) |
|
|
|
|
|
|
26
|
|
|
? $this->_getContainer()->__isset($this->_containerTranslatePropertyName($name)) |
|
27
|
|
|
: null; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function __get($name) { |
|
31
|
|
|
return is_object($this->_getContainer()) |
|
|
|
|
|
|
32
|
|
|
? $this->_getContainer()->__get($this->_containerTranslatePropertyName($name)) |
|
33
|
|
|
: null; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function __unset($name) { |
|
37
|
|
|
if (is_object($this->_getContainer())) { |
|
|
|
|
|
|
38
|
|
|
$this->_getContainer()->__unset($this->_containerTranslatePropertyName($name)); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Is container contains no data |
|
44
|
|
|
* |
|
45
|
|
|
* @return bool |
|
46
|
|
|
*/ |
|
47
|
|
|
public function isEmpty() { |
|
48
|
|
|
return is_object($this->_getContainer()) ? $this->_getContainer()->isEmpty() : false; |
|
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Clears container contents |
|
53
|
|
|
*/ |
|
54
|
|
|
public function clear() { |
|
55
|
|
|
if (is_object($this->_getContainer())) { |
|
|
|
|
|
|
56
|
|
|
$this->_getContainer()->clear(); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function __call($name, $arguments) { |
|
61
|
|
|
return is_object($this->_getContainer()) ? call_user_func_array([$this->_getContainer(), $name], $arguments) : null; |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
protected function _containerTranslatePropertyName($name) { |
|
65
|
|
|
return $name; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.