1 | <?php |
||
9 | abstract class AbstractModel { |
||
10 | |||
11 | /** @var array */ |
||
12 | private $attributes = []; |
||
13 | |||
14 | /** @var string */ |
||
15 | protected $description; |
||
16 | |||
17 | /** |
||
18 | * Sets a custom user attribute |
||
19 | * |
||
20 | * @deprecated See: https://github.com/gossi/php-code-generator/issues/29 |
||
21 | * @param string $key |
||
22 | * @param mixed $value |
||
23 | * @return $this |
||
24 | */ |
||
25 | public function setAttribute($key, $value) { |
||
26 | $this->attributes[$key] = $value; |
||
27 | |||
28 | return $this; |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * Removes and returns a custom user attribute |
||
33 | * |
||
34 | * @deprecated See: https://github.com/gossi/php-code-generator/issues/29 |
||
35 | * @param string $key |
||
36 | * @return mixed |
||
37 | */ |
||
38 | public function removeAttribute($key) { |
||
39 | $val = $this->attributes[$key]; |
||
40 | unset($this->attributes[$key]); |
||
41 | return $val; |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * Returns a custom user attribute |
||
46 | * |
||
47 | * @deprecated See: https://github.com/gossi/php-code-generator/issues/29 |
||
48 | * @param string $key |
||
49 | * @throws \InvalidArgumentException if the key cannot be found |
||
50 | * @return mixed |
||
51 | */ |
||
52 | public function getAttribute($key) { |
||
53 | if (!isset($this->attributes[$key])) { |
||
54 | throw new \InvalidArgumentException(sprintf('There is no attribute named "%s".', $key)); |
||
55 | } |
||
56 | |||
57 | return $this->attributes[$key]; |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Returns a custom user attribute or the default value if the attribute doesn't exist |
||
62 | * |
||
63 | * @deprecated See: https://github.com/gossi/php-code-generator/issues/29 |
||
64 | * @param string $key |
||
65 | * @param mixed $default |
||
66 | * @return mixed |
||
67 | */ |
||
68 | public function getAttributeOrElse($key, $default) { |
||
69 | if (!isset($this->attributes[$key])) { |
||
70 | return $default; |
||
71 | } |
||
72 | |||
73 | return $this->attributes[$key]; |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * Checks whether an attribute exists |
||
78 | * |
||
79 | * @deprecated See: https://github.com/gossi/php-code-generator/issues/29 |
||
80 | * @param string $key |
||
81 | * @return bool |
||
82 | */ |
||
83 | public function hasAttribute($key) { |
||
84 | return isset($this->attributes[$key]); |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * Sets custom user attributes |
||
89 | * |
||
90 | * @deprecated See: https://github.com/gossi/php-code-generator/issues/29 |
||
91 | * @param array $attrs |
||
92 | * @return $this |
||
93 | */ |
||
94 | public function setAttributes(array $attrs) { |
||
95 | $this->attributes = $attrs; |
||
96 | |||
97 | return $this; |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * Returns all custom user attributes |
||
102 | * |
||
103 | * @deprecated See: https://github.com/gossi/php-code-generator/issues/29 |
||
104 | * @return array |
||
105 | */ |
||
106 | public function getAttributes() { |
||
107 | return $this->attributes; |
||
108 | } |
||
109 | |||
110 | /** |
||
111 | * Returns this description |
||
112 | * |
||
113 | * @return string |
||
114 | */ |
||
115 | 24 | public function getDescription() { |
|
118 | |||
119 | /** |
||
120 | * Sets the description, which will also be used when generating a docblock |
||
121 | * |
||
122 | * @param string|array $description |
||
123 | * @return $this |
||
124 | */ |
||
125 | 19 | public function setDescription($description) { |
|
132 | |||
133 | } |
||
134 |