Skip to content
This repository has been archived by the owner. It is now read-only.

Add request object #563

Merged
merged 12 commits into from Nov 2, 2014
Merged

Add request object #563

merged 12 commits into from Nov 2, 2014

Conversation

@rmccue
Copy link
Member

rmccue commented Nov 1, 2014

This is essentially a bag of everything relating to the request.

Fixes #552.

@rmccue
Copy link
Member Author

rmccue commented Nov 1, 2014

@WP-API/amigos #reviewmerge

@rmccue rmccue added this to the 2.0 milestone Nov 1, 2014
rmccue added 3 commits Nov 1, 2014
Also changes get_param to use POST (if relevant), then GET, then the URL
parameters. This mirrors the previous behaviour from v1.
protected $route;

/**
* Attributes (options) for the route that was matched

This comment has been minimized.

Copy link
@danielbachhuber

danielbachhuber Nov 1, 2014

Member

What are some example options?

This comment has been minimized.

Copy link
@rmccue

rmccue Nov 2, 2014

Author Member

Added documentation; this is the array used in the registration.

@danielbachhuber
Copy link
Member

danielbachhuber commented Nov 1, 2014

Generally, I like this idea a lot. The conservative side of me wonders if it's too magical for core.

@nacin @markjaquith opinions? To summarize, the default argument to our new WP_JSON_Controller class is object implementing ArrayAccess so it can also be used as an array.

*
* @var string
*/
protected $method = '';

This comment has been minimized.

Copy link
@danielbachhuber

danielbachhuber Nov 1, 2014

Member

Should this default to GET?

This comment has been minimized.

Copy link
@rmccue

rmccue Nov 2, 2014

Author Member

I think it's better to not default here so that it's evident if it hasn't been set. I'd even be happy with defaulting to null.


// Compatibility for clients that can't use PUT/PATCH/DELETE
if ( isset( $_GET['_method'] ) ) {
$this->method = strtoupper( $_GET['_method'] );
$request->set_method( strtoupper( $_GET['_method'] ) );

This comment has been minimized.

Copy link
@danielbachhuber

danielbachhuber Nov 1, 2014

Member

Should the strtoupper() happen within set_method() so we can be sure it always conforms? I see you're already using it twice here.

This comment has been minimized.

Copy link
@TimothyBJacobs

TimothyBJacobs Nov 1, 2014

Member

+1 to sanitizing inside the set method.

This comment has been minimized.

Copy link
@rmccue

rmccue Nov 1, 2014

Author Member

I agree, I kept it this way to match PSR-7 though. I've no strong argument either way, but it's nice being compatible-ish with PSR-7.

This comment has been minimized.

Copy link
@TimothyBJacobs

TimothyBJacobs Nov 2, 2014

Member

Does PSR-7 mean that two strings with the same value, but different case are different methods?

plugin.php Outdated
*
* This ensures that the request is consistent.
*
* @param array|WP_JSON_Request $reques Request to check.

This comment has been minimized.

Copy link
@danielbachhuber

danielbachhuber Nov 1, 2014

Member

Typo: $reques

@rmccue
Copy link
Member Author

rmccue commented Nov 2, 2014

Updated as per review.

Generally, I like this idea a lot. The conservative side of me wonders if it's too magical for core.

The ArrayAccess is a bit magical, but I don't think it's any worse than things like WP_Post using the post fields or falling back to meta otherwise.

I'm going to go ahead and merge this, as I think we're OK with the idea as a whole, and we can PR any other changes we want here.

rmccue added a commit that referenced this pull request Nov 2, 2014
Add request object
@rmccue rmccue merged commit 5478d4f into joes-registration Nov 2, 2014
1 check passed
1 check passed
continuous-integration/travis-ci The Travis CI build passed
Details
@rmccue rmccue deleted the two-request-object branch Nov 2, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.