summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-05-13 10:40:49 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-05-13 10:40:49 +0200
commita152e320f6aa98774950eb088588cd16387226f8 (patch)
tree4af5190252e9229dd90c84213fcad07950f65822 /lib
parentc06063255f8d93b32452e19819f39cb53d5d4ae3 (diff)
downloadnextcloud-server-a152e320f6aa98774950eb088588cd16387226f8.tar.gz
nextcloud-server-a152e320f6aa98774950eb088588cd16387226f8.zip
make it possible to omit parameters and use the default parameters from the controller method
Diffstat (limited to 'lib')
-rw-r--r--lib/private/appframework/http/dispatcher.php4
-rw-r--r--lib/private/appframework/utility/controllermethodreflector.php9
2 files changed, 9 insertions, 4 deletions
diff --git a/lib/private/appframework/http/dispatcher.php b/lib/private/appframework/http/dispatcher.php
index 39ca3398c66..442e33ee726 100644
--- a/lib/private/appframework/http/dispatcher.php
+++ b/lib/private/appframework/http/dispatcher.php
@@ -126,11 +126,11 @@ class Dispatcher {
// valid types that will be casted
$types = array('int', 'integer', 'bool', 'boolean', 'float');
- foreach($this->reflector->getParameters() as $param) {
+ foreach($this->reflector->getParameters() as $param => $default) {
// try to get the parameter from the request object and cast
// it to the type annotated in the @param annotation
- $value = $this->request->getParam($param);
+ $value = $this->request->getParam($param, $default);
$type = $this->reflector->getType($param);
// if this is submitted using GET or a POST form, 'false' should be
diff --git a/lib/private/appframework/utility/controllermethodreflector.php b/lib/private/appframework/utility/controllermethodreflector.php
index c9cdadcca4a..a1519c72809 100644
--- a/lib/private/appframework/utility/controllermethodreflector.php
+++ b/lib/private/appframework/utility/controllermethodreflector.php
@@ -59,7 +59,12 @@ class ControllerMethodReflector {
// get method parameters
foreach ($reflection->getParameters() as $param) {
- $this->parameters[] = $param->name;
+ if($param->isOptional()) {
+ $default = $param->getDefaultValue();
+ } else {
+ $default = null;
+ }
+ $this->parameters[$param->name] = $default;
}
}
@@ -81,7 +86,7 @@ class ControllerMethodReflector {
/**
- * @return array the arguments of the method
+ * @return array the arguments of the method with key => default value
*/
public function getParameters() {
return $this->parameters;