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

Named parameters in generic proxy API events #10764

Merged
merged 4 commits into from Oct 30, 2016
Merged

Conversation

tsteur
Copy link
Member

@tsteur tsteur commented Oct 18, 2016

When an API method is called, we post some generic events: API.Request.dispatch, API.Request.dispatch.end, API.$plugin.$apiAction, and API.$plugin.$apiAction.end see
https://developer.piwik.org/api-reference/events#apipluginnamemethodname

Those events are meant to change API parameters, the response and to perform other logic when any API method is called. As an argument they post a parameter $finalParameters = array(5, 10, 'foo', 'bar') meaning a plugin needs to access those parameters like $finalParameters[0].

This is quite fragile if the order of an API method ever changes and it is very hard to read the code as it is not clear which value is behind that key. Therefore we will now pass named parameters there and it will now look like: $finalParameters = array('idSite' => 5, 'idGoal' => 10, 'name' => 'foo', 'attribute' => 'bar').

This way it is better to read and easier to access parameters and less fragile as the order of parameters in our API methods could always change.

@tsteur tsteur added the Needs Review PRs that need a code review label Oct 18, 2016
@tsteur tsteur added this to the 3.0.0-b2 milestone Oct 18, 2016
@tsteur tsteur changed the title Named parameters in generic API events Named parameters in generic proxy API events Oct 18, 2016
@tsteur tsteur merged commit f0f2fc2 into 3.x-dev Oct 30, 2016
@tsteur tsteur deleted the namedparams_apievents branch October 30, 2016 20:08
@sgiehl
Copy link
Member

sgiehl commented Oct 30, 2016

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review PRs that need a code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants