1212abstract class AbstractObject implements ArrayAccess, Arrayable, Jsonable, JsonSerializable
1313{
1414
15- /**
16- * @param array $properties
17- */
15+ /**
16+ * @param array $properties
17+ */
1818 public function __construct (array $ properties = [])
1919 {
2020 foreach ($ properties as $ k => $ v ) {
2121 $ this ->$ k = $ v ;
2222 }
2323 }
2424
25- /**
26- * @param string $name
27- */
25+ /**
26+ * @param string $name
27+ */
2828 final public function __get ($ name )
2929 {
3030 throw new LogicException ($ this ->getUndefinedErrorMessage ("\${$ name } property " ));
3131 }
3232
33- /**
34- * @param string $name
35- * @param mixed $value
36- */
33+ /**
34+ * @param string $name
35+ * @param mixed $value
36+ */
3737 final public function __set ($ name , $ value )
3838 {
3939 throw new LogicException ($ this ->getUndefinedErrorMessage ("\${$ name } property " ));
4040 }
4141
42- /**
43- * @param string $name
44- * @param array $arguments
45- */
42+ /**
43+ * @param string $name
44+ * @param array $arguments
45+ */
4646 final public function __call ($ name , $ arguments )
4747 {
4848 throw new LogicException ($ this ->getUndefinedErrorMessage ("{$ name }() method " ));
4949 }
5050
51- /**
52- * @param string $offset
53- *
54- * @return bool
55- */
51+ /**
52+ * @param string $offset
53+ *
54+ * @return bool
55+ */
5656 final public function offsetExists ($ offset )
5757 {
5858 return isset ($ this ->$ offset );
5959 }
6060
61- /**
62- * @param string $offset
63- *
64- * @return mixed
65- */
61+ /**
62+ * @param string $offset
63+ *
64+ * @return mixed
65+ */
6666 final public function offsetGet ($ offset )
6767 {
6868 return $ this ->$ offset ;
6969 }
7070
71- /**
72- * @param string $offset
73- * @param mixed $value
74- */
71+ /**
72+ * @param string $offset
73+ * @param mixed $value
74+ */
7575 final public function offsetSet ($ offset , $ value )
7676 {
7777 $ this ->$ offset = $ value ;
7878 }
7979
80- /**
81- * @param string $offset
82- */
80+ /**
81+ * @param string $offset
82+ */
8383 final public function offsetUnset ($ offset )
8484 {
8585 unset($ this ->$ offset );
8686 }
8787
88- /**
89- * @return array
90- */
88+ /**
89+ * @return array
90+ */
9191 public function toArray ()
9292 {
9393 $ vars = (function ($ that ) {
94- // Only public variables
94+ // Only public variables
9595 return get_object_vars ($ that );
9696 })(
9797 $ this
@@ -100,11 +100,11 @@ public function toArray()
100100 return $ this ->exportValue ($ vars );
101101 }
102102
103- /**
104- * @param mixed $value
105- *
106- * @return array|mixed
107- */
103+ /**
104+ * @param mixed $value
105+ *
106+ * @return array|mixed
107+ */
108108 private function exportValue ($ value )
109109 {
110110 if ($ value instanceof RawValue) {
@@ -118,15 +118,15 @@ private function exportValue($value)
118118 if (is_array ($ value )) {
119119 $ result = [];
120120 foreach ($ value as $ k => $ v ) {
121- // Ignore null properties
121+ // Ignore null properties
122122 if (is_null ($ v )) {
123123 continue ;
124124 }
125- // Transform extension property names
125+ // Transform extension property names
126126 if (preg_match ('/^x[A-Z]/ ' , $ k )) {
127127 $ k = 'x- ' . lcfirst (preg_replace ('/^(x)/ ' , '' , $ k ));
128128 }
129- // Transform reference property names
129+ // Transform reference property names
130130 if ($ k === 'ref ' ) {
131131 $ k = '$ref ' ;
132132 }
@@ -142,22 +142,22 @@ private function exportValue($value)
142142 return $ value ;
143143 }
144144
145- /**
146- * @param int $options
147- *
148- * @return string
149- */
145+ /**
146+ * @param int $options
147+ *
148+ * @return string
149+ */
150150 public function toJson ($ options = 0 )
151151 {
152152 return json_encode ($ this , $ options );
153153 }
154154
155- /**
156- * @param int $inline
157- * @param int $indentation
158- * @param int $flags
159- * @return string
160- */
155+ /**
156+ * @param int $inline
157+ * @param int $indentation
158+ * @param int $flags
159+ * @return string
160+ */
161161 public function toYaml (
162162 int $ inline = 10 ,
163163 int $ indentation = 2 ,
@@ -166,19 +166,19 @@ public function toYaml(
166166 return Yaml::dump ($ this ->toArray (), $ inline , $ indentation , $ flags );
167167 }
168168
169- /**
170- * @return array
171- */
169+ /**
170+ * @return array
171+ */
172172 public function jsonSerialize ()
173173 {
174174 return $ this ->toArray ();
175175 }
176176
177- /**
178- * @param string $name
179- *
180- * @return string
181- */
177+ /**
178+ * @param string $name
179+ *
180+ * @return string
181+ */
182182 private function getUndefinedErrorMessage (string $ name ): string
183183 {
184184 return static ::class . ":: {$ name } is not defined. Dynamic access is disabled for DTOs. " ;
0 commit comments