1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* File: Mask.php |
4
|
|
|
* Category: Mask |
5
|
|
|
* Author: M.Goldenbaum |
6
|
|
|
* Created: 14.03.19 20:49 |
7
|
|
|
* Updated: - |
8
|
|
|
* |
9
|
|
|
* Description: |
10
|
|
|
* - |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Webklex\IMAP\Support\Masks; |
14
|
|
|
|
15
|
|
|
use Webklex\IMAP\Exceptions\MethodNotFoundException; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class Mask |
19
|
|
|
* |
20
|
|
|
* @package Webklex\IMAP\Support\Masks |
21
|
|
|
*/ |
22
|
|
|
class Mask { |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var array $attributes |
26
|
|
|
*/ |
27
|
|
|
protected $attributes = []; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var object $parent |
31
|
|
|
*/ |
32
|
|
|
protected $parent; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Mask constructor. |
36
|
|
|
* @param $parent |
37
|
|
|
*/ |
38
|
|
|
public function __construct($parent) { |
39
|
|
|
$this->parent = $parent; |
40
|
|
|
|
41
|
|
|
if(method_exists($this->parent, 'getAttributes')){ |
42
|
|
|
$this->attributes = array_merge($this->attributes, $this->parent->getAttributes()); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$this->boot(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Boot method made to be used by any custom mask |
50
|
|
|
*/ |
51
|
|
|
protected function boot(){} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Call dynamic attribute setter and getter methods and inherit the parent calls |
55
|
|
|
* @param string $method |
56
|
|
|
* @param array $arguments |
57
|
|
|
* |
58
|
|
|
* @return mixed |
59
|
|
|
* @throws MethodNotFoundException |
60
|
|
|
*/ |
61
|
|
|
public function __call($method, $arguments) { |
62
|
|
|
if(strtolower(substr($method, 0, 3)) === 'get') { |
63
|
|
|
$name = snake_case(substr($method, 3)); |
|
|
|
|
64
|
|
|
|
65
|
|
|
if(isset($this->attributes[$name])) { |
66
|
|
|
return $this->attributes[$name]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
}elseif (strtolower(substr($method, 0, 3)) === 'set') { |
70
|
|
|
$name = snake_case(substr($method, 3)); |
|
|
|
|
71
|
|
|
|
72
|
|
|
if(isset($this->attributes[$name])) { |
73
|
|
|
$this->attributes[$name] = array_pop($arguments); |
74
|
|
|
|
75
|
|
|
return $this->attributes[$name]; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
if(method_exists($this->parent, $method) === true){ |
81
|
|
|
return call_user_func_array([$this->parent, $method], $arguments); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
throw new MethodNotFoundException("Method ".self::class.'::'.$method.'() is not supported'); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param $name |
89
|
|
|
* @param $value |
90
|
|
|
* |
91
|
|
|
* @return mixed |
92
|
|
|
*/ |
93
|
|
|
public function __set($name, $value) { |
94
|
|
|
$this->attributes[$name] = $value; |
95
|
|
|
|
96
|
|
|
return $this->attributes[$name]; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param $name |
101
|
|
|
* |
102
|
|
|
* @return mixed|null |
103
|
|
|
*/ |
104
|
|
|
public function __get($name) { |
105
|
|
|
if(isset($this->attributes[$name])) { |
106
|
|
|
return $this->attributes[$name]; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
return null; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @return mixed |
114
|
|
|
*/ |
115
|
|
|
public function getParent(){ |
116
|
|
|
return $this->parent; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @return array |
121
|
|
|
*/ |
122
|
|
|
public function getAttributes(){ |
123
|
|
|
return $this->attributes; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
} |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.