Browse Source

+ Added dependencies to model for reset calculated properties

Visman 6 years ago
parent
commit
dbd0fe8535
1 changed files with 14 additions and 0 deletions
  1. 14 0
      app/Models/Model.php

+ 14 - 0
app/Models/Model.php

@@ -25,6 +25,12 @@ class Model
      */
     protected $aCalc = [];
 
+    /**
+     * Зависимости свойств
+     * @var array
+     */
+    protected $dependProp = [];
+
     /**
      * Конструктор
      *
@@ -58,6 +64,10 @@ class Model
     {
         unset($this->a[$name]);     //????
         unset($this->aCalc[$name]); //????
+
+        if (isset($this->dependProp[$name])) {
+            $this->aCalc = \array_diff_key($this->aCalc, \array_flip($this->dependProp[$name]));
+        }
     }
 
     /**
@@ -70,6 +80,10 @@ class Model
     {
         unset($this->aCalc[$name]);
 
+        if (isset($this->dependProp[$name])) {
+            $this->aCalc = \array_diff_key($this->aCalc, \array_flip($this->dependProp[$name]));
+        }
+
         if (\method_exists($this, $method = 'set' . $name)) {
             $this->$method($val);
         } else {