mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Reworking parameter munging specific to requestAction into requestAction. Updating tests cases for Object. As request->data is an array() not null. And leading / is trimmed off of [url][url].
This commit is contained in:
parent
55cc3296ab
commit
f02e0483ee
3 changed files with 23 additions and 35 deletions
|
@ -87,19 +87,8 @@ class Dispatcher {
|
||||||
* are encountered.
|
* are encountered.
|
||||||
*/
|
*/
|
||||||
public function dispatch(CakeRequest $request, $additionalParams = array()) {
|
public function dispatch(CakeRequest $request, $additionalParams = array()) {
|
||||||
/* Should move to Object::requestAction()
|
|
||||||
if (is_array($url)) {
|
|
||||||
$url = $this->_extractParams($url, $additionalParams);
|
|
||||||
}
|
|
||||||
if ($url instanceof CakeRequest) {
|
|
||||||
$request = $url;
|
|
||||||
} else {
|
|
||||||
$request = new CakeRequest($url);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
$this->here = $request->here;
|
$this->here = $request->here;
|
||||||
|
|
||||||
|
|
||||||
if ($this->asset($request->url) || $this->cached($request->url)) {
|
if ($this->asset($request->url) || $this->cached($request->url)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -180,22 +169,6 @@ class Dispatcher {
|
||||||
$response->send();
|
$response->send();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the params when $url is passed as an array to Object::requestAction();
|
|
||||||
* Merges the $url and $additionalParams and creates a string url.
|
|
||||||
*
|
|
||||||
* @param array $url Array or request parameters
|
|
||||||
* @param array $additionalParams Array of additional parameters.
|
|
||||||
* @return string $url The generated url string.
|
|
||||||
*/
|
|
||||||
protected function _extractParams($url, $additionalParams = array()) {
|
|
||||||
$defaults = array('pass' => array(), 'named' => array(), 'form' => array());
|
|
||||||
$params = array_merge($defaults, $url, $additionalParams);
|
|
||||||
|
|
||||||
$params += array('base' => false, 'url' => array());
|
|
||||||
return ltrim(Router::reverse($params), '/');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns array of GET and POST parameters. GET parameters are taken from given URL.
|
* Returns array of GET and POST parameters. GET parameters are taken from given URL.
|
||||||
*
|
*
|
||||||
|
|
|
@ -67,7 +67,7 @@ class Object {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!class_exists('dispatcher')) {
|
if (!class_exists('dispatcher')) {
|
||||||
require CAKE . 'dispatcher.php';
|
require LIBS . 'dispatcher.php';
|
||||||
}
|
}
|
||||||
if (in_array('return', $extra, true)) {
|
if (in_array('return', $extra, true)) {
|
||||||
$extra = array_merge($extra, array('return' => 0, 'autoRender' => 1));
|
$extra = array_merge($extra, array('return' => 0, 'autoRender' => 1));
|
||||||
|
@ -75,9 +75,21 @@ class Object {
|
||||||
if (is_array($url) && !isset($extra['url'])) {
|
if (is_array($url) && !isset($extra['url'])) {
|
||||||
$extra['url'] = array();
|
$extra['url'] = array();
|
||||||
}
|
}
|
||||||
$params = array_merge(array('autoRender' => 0, 'return' => 1, 'bare' => 1, 'requested' => 1), $extra);
|
$extra = array_merge(array('autoRender' => 0, 'return' => 1, 'bare' => 1, 'requested' => 1), $extra);
|
||||||
$dispatcher = new Dispatcher;
|
|
||||||
return $dispatcher->dispatch($url, $params);
|
if (is_string($url)) {
|
||||||
|
$request = new CakeRequest($url);
|
||||||
|
} elseif (is_array($url)) {
|
||||||
|
$params = $url + array('pass' => array(), 'named' => array(), 'base' => false);
|
||||||
|
$params = array_merge($params, $extra);
|
||||||
|
$request = new CakeRequest(Router::reverse($params), false);
|
||||||
|
if (isset($params['data'])) {
|
||||||
|
$request->data = $params['data'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$dispatcher = new Dispatcher();
|
||||||
|
return $dispatcher->dispatch($request, $extra);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -824,7 +824,7 @@ class ObjectTest extends CakeTestCase {
|
||||||
function testRequestActionParamParseAndPass() {
|
function testRequestActionParamParseAndPass() {
|
||||||
$result = $this->object->requestAction('/request_action/params_pass');
|
$result = $this->object->requestAction('/request_action/params_pass');
|
||||||
$this->assertTrue(isset($result['url']['url']));
|
$this->assertTrue(isset($result['url']['url']));
|
||||||
$this->assertEqual($result['url']['url'], '/request_action/params_pass');
|
$this->assertEqual($result['url']['url'], 'request_action/params_pass');
|
||||||
$this->assertEqual($result['controller'], 'request_action');
|
$this->assertEqual($result['controller'], 'request_action');
|
||||||
$this->assertEqual($result['action'], 'params_pass');
|
$this->assertEqual($result['action'], 'params_pass');
|
||||||
$this->assertEqual($result['form'], array());
|
$this->assertEqual($result['form'], array());
|
||||||
|
@ -855,9 +855,12 @@ class ObjectTest extends CakeTestCase {
|
||||||
));
|
));
|
||||||
$result = $this->object->requestAction(array('controller' => 'request_action', 'action' => 'post_pass'));
|
$result = $this->object->requestAction(array('controller' => 'request_action', 'action' => 'post_pass'));
|
||||||
$expected = null;
|
$expected = null;
|
||||||
$this->assertEqual($expected, $result);
|
$this->assertEmpty($result);
|
||||||
|
|
||||||
$result = $this->object->requestAction(array('controller' => 'request_action', 'action' => 'post_pass'), array('data' => $_POST['data']));
|
$result = $this->object->requestAction(
|
||||||
|
array('controller' => 'request_action', 'action' => 'post_pass'),
|
||||||
|
array('data' => $_POST['data'])
|
||||||
|
);
|
||||||
$expected = $_POST['data'];
|
$expected = $_POST['data'];
|
||||||
$this->assertEqual($expected, $result);
|
$this->assertEqual($expected, $result);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue