From 7adc198a52071db82779c1b9a570577cad0609ad Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Tue, 27 Apr 2021 20:56:13 +0000 Subject: [PATCH] [ENTITY] Add meta method 'have*' to Entity base class, which checks if a field 'isset' --- src/Core/Entity.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Core/Entity.php b/src/Core/Entity.php index 7f3a75a7db..a915541487 100644 --- a/src/Core/Entity.php +++ b/src/Core/Entity.php @@ -31,6 +31,15 @@ use DateTime; */ abstract class Entity { + public function __call(string $name , array $arguments): mixed + { + if (Formatting::startsWith($name, 'have')) { + $prop = Formatting::camelCaseToSnakeCase(Formatting::removePrefix($name, 'have')); + return isset($this->{$prop}); + } + throw new \Exception("Entity::{$name} called with bogus arguments: " . print_r($arguments, true)); + } + /** * Create an instance of the called class or fill in the * properties of $obj with the associative array $args. Doesn't