diff options
author | Daniel Kesselberg <mail@danielkesselberg.de> | 2019-11-14 21:57:43 +0300 |
---|---|---|
committer | Daniel Kesselberg <mail@danielkesselberg.de> | 2019-11-16 02:39:48 +0300 |
commit | a27c10daa66a38c453393fcaf0c545d60f041f30 (patch) | |
tree | 25eb759f6a1856feebb1ef99556543910aa64064 /lib/public | |
parent | 51d3f98bfb83b632be6223a5d928d57e8e52e942 (diff) |
Make isXXX available for bool properties only
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
Diffstat (limited to 'lib/public')
-rw-r--r-- | lib/public/AppFramework/Db/Entity.php | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/lib/public/AppFramework/Db/Entity.php b/lib/public/AppFramework/Db/Entity.php index 091b90257b4..8bd537211fc 100644 --- a/lib/public/AppFramework/Db/Entity.php +++ b/lib/public/AppFramework/Db/Entity.php @@ -87,7 +87,7 @@ abstract class Entity { return $this->_fieldTypes; } - + /** * Marks the entity as clean needed for setting the id after the insertion * @since 7.0.0 @@ -115,7 +115,7 @@ abstract class Entity { $this->$name = $args[0]; } else { - throw new \BadFunctionCallException($name . + throw new \BadFunctionCallException($name . ' is not a valid attribute'); } } @@ -129,7 +129,7 @@ abstract class Entity { if(property_exists($this, $name)){ return $this->$name; } else { - throw new \BadFunctionCallException($name . + throw new \BadFunctionCallException($name . ' is not a valid attribute'); } } @@ -137,7 +137,7 @@ abstract class Entity { /** * Each time a setter is called, push the part after set - * into an array: for instance setId will save Id in the + * into an array: for instance setId will save Id in the * updated fields array so it can be easily used to create the * getter method * @since 7.0.0 @@ -147,7 +147,7 @@ abstract class Entity { $this->setter(lcfirst(substr($methodName, 3)), $args); } elseif (strpos($methodName, 'get') === 0) { return $this->getter(lcfirst(substr($methodName, 3))); - } elseif (strpos($methodName, 'is') === 0) { + } elseif ($this->isGetterForBoolProperty($methodName)) { return $this->getter(lcfirst(substr($methodName, 2))); } else { throw new \BadFunctionCallException($methodName . @@ -156,6 +156,18 @@ abstract class Entity { } + /** + * @param string $methodName + * @return bool + * @since 18.0.0 + */ + protected function isGetterForBoolProperty(string $methodName): bool { + if (strpos($methodName, 'is') === 0) { + $fieldName = lcfirst(substr($methodName, 2)); + return isset($this->_fieldTypes[$fieldName]) && strpos($this->_fieldTypes[$fieldName], 'bool') === 0; + } + return false; + } /** * Mark am attribute as updated @@ -168,7 +180,7 @@ abstract class Entity { /** - * Transform a database columnname to a property + * Transform a database columnname to a property * @param string $columnName the name of the column * @return string the property name * @since 7.0.0 |