Browse Source

+ Added a way to get the original value of a single property for a DataModel

Visman 6 years ago
parent
commit
0b13e3562d
1 changed files with 18 additions and 1 deletions
  1. 18 1
      app/Models/DataModel.php

+ 18 - 1
app/Models/DataModel.php

@@ -91,7 +91,7 @@ class DataModel extends Model
         // без отслеживания
         if (\strpos($name, '__') === 0) {
             $track = null;
-            $name  = substr($name, 2);
+            $name  = \substr($name, 2);
         // с отслеживанием
         } else {
             $track = false;
@@ -117,4 +117,21 @@ class DataModel extends Model
             $this->modified[$name] = true;
         }
     }
+
+    /**
+     * Возвращает значение свойства
+     *
+     * @param string $name
+     *
+     * @return mixed
+     */
+    public function __get($name)
+    {
+        if (\strpos($name, '__') === 0) {
+            $name = \substr($name, 2);
+            return isset($this->a[$name]) ? $this->a[$name] : null;
+        } else {
+            return parent::__get($name);
+        }
+    }
 }