aboutsummaryrefslogtreecommitdiff
path: root/app/class/Dbitem.php
diff options
context:
space:
mode:
authorvincent-peugnet <v.peugnet@free.fr>2020-01-29 02:34:50 +0100
committervincent-peugnet <v.peugnet@free.fr>2020-01-29 02:34:50 +0100
commit64ac1605b6fe8e997134dd57cc30f30b99ebc076 (patch)
treed4fd89c68f0f0eb7b49ea92336f8f8ab5f778e45 /app/class/Dbitem.php
parentb6173772bdef1eaf067573373ab500d67dfc454d (diff)
downloadwcms-64ac1605b6fe8e997134dd57cc30f30b99ebc076.tar.gz
wcms-64ac1605b6fe8e997134dd57cc30f30b99ebc076.zip
refactor : item abstract class
new Item abstract class with hydrate and dry functions to clean others
Diffstat (limited to 'app/class/Dbitem.php')
-rw-r--r--app/class/Dbitem.php34
1 files changed, 13 insertions, 21 deletions
diff --git a/app/class/Dbitem.php b/app/class/Dbitem.php
index fb272b1..34814d2 100644
--- a/app/class/Dbitem.php
+++ b/app/class/Dbitem.php
@@ -2,33 +2,25 @@
namespace Wcms;
-class Dbitem
+use DateTime;
+use DateTimeImmutable;
+
+abstract class Dbitem extends 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) {
+ if($value instanceof DateTime || $value instanceof DateTimeImmutable) {
+ $array[$var] = $this->$var('string');
+ } else {
+ $array[$var] = $this->$var();
}
}
-
- }
-
- public function dry()
- {
- $array = [];
- foreach (get_object_vars($this) as $var => $value) {
- if (in_array($var, $this::VAR_DATE)) {
- $array[$var] = $this->$var('string');
- } else {
- $array[$var] = $this->$var();
- }
- }
return $array;
}
-}
+}
?> \ No newline at end of file