summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2019-11-26 12:25:36 +0100
committerGitHub <noreply@github.com>2019-11-26 12:25:36 +0100
commitb607e3e6f41853600dd90820e82ceab5859c13c5 (patch)
tree0382be10cccbb44ac669ed53aeb21acc7a806560 /lib
parente3bee2cb782b4897e4822c909d1dbbf2637f7b65 (diff)
parenta27c10daa66a38c453393fcaf0c545d60f041f30 (diff)
downloadnextcloud-server-b607e3e6f41853600dd90820e82ceab5859c13c5.tar.gz
nextcloud-server-b607e3e6f41853600dd90820e82ceab5859c13c5.zip
Merge pull request #17948 from nextcloud/enh/check-if-property-is-bool
Make isXXX available for bool properties only
Diffstat (limited to 'lib')
-rw-r--r--lib/public/AppFramework/Db/Entity.php24
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