Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(resolver): Add support for get parameters #472

Merged
merged 11 commits into from
Jun 2, 2018

Conversation

Cawllec
Copy link
Contributor

@Cawllec Cawllec commented Mar 26, 2018

  • Adds support for get parameters in the basic resolver
  • Retains support for $_POST and other method parameters.

@@ -103,6 +103,23 @@ public function testGetMetaDataWithPost()
$this->assertSame(['request' => $data], $this->resolver->resolve()->getMetaData());
}

public function testGetMetaDataWithGet()
{
$_SERVER['REQUEST_METHOD'] = 'GET';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would happen with lesser used request methods like HEAD or PATCH? Is it worth covering them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They don't have server variables and the data should be dropped into either the json_decode section due to application/json being present, or the parse_str section if not. I'll do some manual testing on this to verify these cases are covered however.

{
static $result;

if ($result !== null) {
return $result ?: null;
}

$result = $post ?: static::parseInput($server, static::readInput());
if (isset($server['REQUEST_METHOD']) && strtoupper($server['REQUEST_METHOD']) === 'GET') {
$result = $_GET;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Access to superglobals was intentionally omitted from anything other than the resolve method. Perhaps put it back there, so that this method is not messing with global state?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it matter if the method is only being called statically from within the resolve method?

@@ -16,7 +16,7 @@ public function resolve()
empty($_SESSION) ? [] : $_SESSION,
empty($_COOKIE) ? [] : $_COOKIE,
static::getRequestHeaders($_SERVER),
static::getInputParams($_SERVER, $_POST));
static::getInputParams($_SERVER));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking the request method should instead happen here, and pass the correct variable array (get vs post variables) into getInputParams. It reduces the amount of "magic" going on throughout.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the current implementation if $_GET is empty in a GET request the method will attempt to pull body parameters from php://input, something that it shouldn't do for GET requests.
I'd suggest splitting getInputParams into multiple methods to handle GET and other request methods separately, or add an argument that determines whether the php://input source should be read or not.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, checking whether to read from php://input should be done by request type, either in a single place or via a flag. I'm not suggesting that input should be read for GET requests.

@Cawllec
Copy link
Contributor Author

Cawllec commented May 1, 2018

Ok, I've refactored it somewhat so that the superglobals $_SERVER, $_POST, and $_GET are accessed only in the resolve method, and passed through to getInputParams as before.

I've added a flag, $is_get to the method in order to determine whether the parseInput methods should be called.

The result doesn't effect the output, so the tests have remained the same.

Cawllec and others added 2 commits May 10, 2018 11:19
@kattrali kattrali changed the title feature(get parameters): Add support for get parameters feature(resolver): Add support for get parameters May 21, 2018
Show that the parameter is intended to determine whether input should be
used as a params fallback if it is not otherwise present
@kattrali kattrali changed the base branch from master to next June 2, 2018 01:20
@kattrali kattrali dismissed GrahamCampbell’s stale review June 2, 2018 01:21

Concerns resolved inline

@kattrali kattrali merged commit 028860d into next Jun 2, 2018
@kattrali kattrali deleted the cawllec/add-get-params branch June 2, 2018 01:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants