diff options
Diffstat (limited to 'app/class/Item.php')
-rw-r--r-- | app/class/Item.php | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/app/class/Item.php b/app/class/Item.php new file mode 100644 index 0000000..526e630 --- /dev/null +++ b/app/class/Item.php @@ -0,0 +1,50 @@ +<?php + +namespace Wcms; + +abstract class Item +{ + + + public function hydrate($datas = []) + { + foreach ($datas as $key => $value) { + $method = 'set' . $key; + + if (method_exists($this, $method)) { + $this->$method($value); + } + } + } + + + public function dry() + { + $array = []; + foreach ($this as $var => $value) { + $array[$var] = $this->$var(); + } + return $array; + } + + + /** + * Return any asked vars and their values of an object as associative array + * + * @param array $vars list of vars + * @return array Associative array `$var => $value` + */ + public function drylist(array $vars) : array + { + $array = []; + foreach ($vars as $var) { + if (property_exists($this, $var)) + $array[$var] = $this->$var; + } + return $array; + } + +} + + +?>
\ No newline at end of file |