aboutsummaryrefslogtreecommitdiff
path: root/app/class/Item.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/class/Item.php')
-rw-r--r--app/class/Item.php39
1 files changed, 36 insertions, 3 deletions
diff --git a/app/class/Item.php b/app/class/Item.php
index a76e700..76fa78e 100644
--- a/app/class/Item.php
+++ b/app/class/Item.php
@@ -29,14 +29,47 @@ abstract class Item
}
}
-
public function dry()
{
$array = [];
+ $array = $this->obj2array($this, $array);
+ return $array;
+ }
+
+
+ public function obj2array($obj, &$arr)
+ {
+ if (!is_object($obj) && !is_array($obj)) {
+ $arr = $obj;
+ return $arr;
+ }
+ foreach ($obj as $key => $value) {
+ if (!empty($value)) {
+ $arr[$key] = array();
+ $this->obj2array($value, $arr[$key]);
+ } else {
+ $arr[$key] = $value;
+ }
+ }
+ return $arr;
+ }
+
+ public function dryold()
+ {
+ $array = [];
foreach (get_object_vars($this) as $var => $value) {
- $array[$var] = $this->$var();
+ if (is_object($value) && is_subclass_of($value, get_class($this))) {
+ $array[$var] = $value->dry();
+ } else {
+ if (method_exists($this, $var)) {
+ $array[$var] = $this->$var();
+ } else {
+ $array[$var] = $value;
+ }
+ }
}
- return $array;
+ return get_object_vars($this);
+ // return $array;
}