mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Making Dispatcher::parseParams require a CakeRequest object instead of as string url. Updating tests in the Dispatcher, and fixing an issue where POST params would be wiped out by Router.
This commit is contained in:
parent
ffd05ffc3e
commit
fbd70bf23c
3 changed files with 28 additions and 23 deletions
|
@ -90,19 +90,21 @@ class Dispatcher extends Object {
|
|||
* the form of Missing Controllers information. It does the same with Actions (methods of Controllers are called
|
||||
* Actions).
|
||||
*
|
||||
* @param string $url URL information to work on
|
||||
* @param mixed $url Either a string url or a CakeRequest object information to work on. If $url is a string
|
||||
* It will be used to create the request object.
|
||||
* @param array $additionalParams Settings array ("bare", "return") which is melded with the GET and POST params
|
||||
* @return boolean Success
|
||||
*/
|
||||
public function dispatch($url = null, $additionalParams = array()) {
|
||||
if (is_array($url)) {
|
||||
$url = $this->_extractParams($url, $additionalParams);
|
||||
} else {
|
||||
if ($url) {
|
||||
$_GET['url'] = $url;
|
||||
}
|
||||
}
|
||||
$request = $this->parseParams($url, $additionalParams);
|
||||
if ($url instanceof CakeRequest) {
|
||||
$request = $url;
|
||||
} else {
|
||||
$request = new CakeRequest($url);
|
||||
}
|
||||
$request = $this->parseParams($request, $additionalParams);
|
||||
$this->params = $request;
|
||||
|
||||
if ($this->asset($request->url) || $this->cached($request->url)) {
|
||||
|
@ -229,15 +231,15 @@ class Dispatcher extends Object {
|
|||
/**
|
||||
* Returns array of GET and POST parameters. GET parameters are taken from given URL.
|
||||
*
|
||||
* @param string $fromUrl URL to mine for parameter information.
|
||||
* @param CakeRequest $fromUrl CakeRequest object to mine for parameter information.
|
||||
* @return array Parameters found in POST and GET.
|
||||
*/
|
||||
public function parseParams($fromUrl, $additionalParams = array()) {
|
||||
public function parseParams(CakeRequest $request, $additionalParams = array()) {
|
||||
$namedExpressions = Router::getNamedExpressions();
|
||||
extract($namedExpressions);
|
||||
include CONFIGS . 'routes.php';
|
||||
|
||||
$request = Router::parse(new CakeRequest());
|
||||
$request = Router::parse($request);
|
||||
|
||||
if (!empty($additionalParams)) {
|
||||
$request->params = array_merge($request->params, $additionalParams);
|
||||
|
|
|
@ -486,7 +486,7 @@ class Router {
|
|||
$out['url']['ext'] = $ext;
|
||||
}
|
||||
|
||||
$request->params = $out;
|
||||
$request->params = array_merge($request->params, $out);
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
|
|
@ -579,8 +579,8 @@ class DispatcherTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testParseParamsWithoutZerosAndEmptyPost() {
|
||||
$Dispatcher =& new Dispatcher();
|
||||
$test = $Dispatcher->parseParams("/testcontroller/testaction/params1/params2/params3");
|
||||
$Dispatcher = new Dispatcher();
|
||||
$test = $Dispatcher->parseParams(new CakeRequest("/testcontroller/testaction/params1/params2/params3"));
|
||||
$this->assertIdentical($test['controller'], 'testcontroller');
|
||||
$this->assertIdentical($test['action'], 'testaction');
|
||||
$this->assertIdentical($test['pass'][0], 'params1');
|
||||
|
@ -596,9 +596,10 @@ class DispatcherTest extends CakeTestCase {
|
|||
*/
|
||||
public function testParseParamsReturnsPostedData() {
|
||||
$_POST['testdata'] = "My Posted Content";
|
||||
$Dispatcher =& new Dispatcher();
|
||||
$test = $Dispatcher->parseParams("/");
|
||||
$this->assertTrue($test['form'], "Parsed URL not returning post data");
|
||||
$Dispatcher = new Dispatcher();
|
||||
|
||||
$test = $Dispatcher->parseParams(new CakeRequest("/"));
|
||||
$this->assertTrue(isset($test['form']), "Parsed URL not returning post data");
|
||||
$this->assertIdentical($test['form']['testdata'], "My Posted Content");
|
||||
}
|
||||
|
||||
|
@ -608,8 +609,8 @@ class DispatcherTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testParseParamsWithSingleZero() {
|
||||
$Dispatcher =& new Dispatcher();
|
||||
$test = $Dispatcher->parseParams("/testcontroller/testaction/1/0/23");
|
||||
$Dispatcher = new Dispatcher();
|
||||
$test = $Dispatcher->parseParams(new CakeRequest("/testcontroller/testaction/1/0/23"));
|
||||
$this->assertIdentical($test['controller'], 'testcontroller');
|
||||
$this->assertIdentical($test['action'], 'testaction');
|
||||
$this->assertIdentical($test['pass'][0], '1');
|
||||
|
@ -623,8 +624,8 @@ class DispatcherTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testParseParamsWithManySingleZeros() {
|
||||
$Dispatcher =& new Dispatcher();
|
||||
$test = $Dispatcher->parseParams("/testcontroller/testaction/0/0/0/0/0/0");
|
||||
$Dispatcher = new Dispatcher();
|
||||
$test = $Dispatcher->parseParams(new CakeRequest("/testcontroller/testaction/0/0/0/0/0/0"));
|
||||
$this->assertPattern('/\\A(?:0)\\z/', $test['pass'][0]);
|
||||
$this->assertPattern('/\\A(?:0)\\z/', $test['pass'][1]);
|
||||
$this->assertPattern('/\\A(?:0)\\z/', $test['pass'][2]);
|
||||
|
@ -639,8 +640,9 @@ class DispatcherTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testParseParamsWithManyZerosInEachSectionOfUrl() {
|
||||
$Dispatcher =& new Dispatcher();
|
||||
$test = $Dispatcher->parseParams("/testcontroller/testaction/000/0000/00000/000000/000000/0000000");
|
||||
$Dispatcher = new Dispatcher();
|
||||
$request = new CakeRequest("/testcontroller/testaction/000/0000/00000/000000/000000/0000000");
|
||||
$test = $Dispatcher->parseParams($request);
|
||||
$this->assertPattern('/\\A(?:000)\\z/', $test['pass'][0]);
|
||||
$this->assertPattern('/\\A(?:0000)\\z/', $test['pass'][1]);
|
||||
$this->assertPattern('/\\A(?:00000)\\z/', $test['pass'][2]);
|
||||
|
@ -655,8 +657,9 @@ class DispatcherTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testParseParamsWithMixedOneToManyZerosInEachSectionOfUrl() {
|
||||
$Dispatcher =& new Dispatcher();
|
||||
$test = $Dispatcher->parseParams("/testcontroller/testaction/01/0403/04010/000002/000030/0000400");
|
||||
$Dispatcher = new Dispatcher();
|
||||
$request = new CakeRequest("/testcontroller/testaction/01/0403/04010/000002/000030/0000400");
|
||||
$test = $Dispatcher->parseParams($request);
|
||||
$this->assertPattern('/\\A(?:01)\\z/', $test['pass'][0]);
|
||||
$this->assertPattern('/\\A(?:0403)\\z/', $test['pass'][1]);
|
||||
$this->assertPattern('/\\A(?:04010)\\z/', $test['pass'][2]);
|
||||
|
|
Loading…
Add table
Reference in a new issue