Skip to content
Snippets Groups Projects
Commit bb0c88a5 authored by Bernhard Posselt's avatar Bernhard Posselt
Browse files

always set url parameters when they are available in the app dispatch

prefer url parameters passed into the main method. If they are not present, use the containers urlParameters

add space
parent 2fbe8bbc
No related branches found
No related tags found
No related merge requests found
...@@ -75,7 +75,9 @@ class App { ...@@ -75,7 +75,9 @@ class App {
*/ */
public static function main($controllerName, $methodName, DIContainer $container, array $urlParams = null) { public static function main($controllerName, $methodName, DIContainer $container, array $urlParams = null) {
if (!is_null($urlParams)) { if (!is_null($urlParams)) {
$container['urlParams'] = $urlParams; $container['OCP\\IRequest']->setUrlParameters($urlParams);
} else if (isset($container['urlParams']) && !is_null($container['urlParams'])) {
$container['OCP\\IRequest']->setUrlParameters($container['urlParams']);
} }
$appName = $container['AppName']; $appName = $container['AppName'];
......
...@@ -233,7 +233,6 @@ class DIContainer extends SimpleContainer implements IAppContainer { ...@@ -233,7 +233,6 @@ class DIContainer extends SimpleContainer implements IAppContainer {
/** @var $c SimpleContainer */ /** @var $c SimpleContainer */
/** @var $server SimpleContainer */ /** @var $server SimpleContainer */
$server = $c->query('ServerContainer'); $server = $c->query('ServerContainer');
$server->registerParameter('urlParams', $c['urlParams']);
/** @var $server IServerContainer */ /** @var $server IServerContainer */
return $server->getRequest(); return $server->getRequest();
}); });
......
...@@ -107,6 +107,14 @@ class Request implements \ArrayAccess, \Countable, IRequest { ...@@ -107,6 +107,14 @@ class Request implements \ArrayAccess, \Countable, IRequest {
} }
public function setUrlParameters($parameters) {
$this->items['urlParams'] = $parameters;
$this->items['parameters'] = array_merge(
$this->items['parameters'],
$this->items['urlParams']
);
}
// Countable method. // Countable method.
public function count() { public function count() {
return count(array_keys($this->items['parameters'])); return count(array_keys($this->items['parameters']));
......
...@@ -214,4 +214,21 @@ class RequestTest extends \Test\TestCase { ...@@ -214,4 +214,21 @@ class RequestTest extends \Test\TestCase {
$this->fail('Expected LogicException.'); $this->fail('Expected LogicException.');
} }
public function testSetUrlParameters() {
$vars = array(
'post' => array(),
'method' => 'POST',
'urlParams' => array('id' => '2'),
);
$request = new Request($vars, $this->stream);
$newParams = array('id' => '3', 'test' => 'test2');
$request->setUrlParameters($newParams);
$this->assertEquals('test2', $request->getParam('test'));
$this->assertEquals('3', $request->getParam('id'));
$this->assertEquals('3', $request->getParams()['id']);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment