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

Add various helpers #189

Open
bakura10 opened this issue Feb 6, 2015 · 3 comments
Open

Add various helpers #189

bakura10 opened this issue Feb 6, 2015 · 3 comments
Milestone

Comments

@bakura10
Copy link
Member

bakura10 commented Feb 6, 2015

Hi,

To make template more easier to write, we should identify common patterns (even if opiniated). Some ideas I'm often using:

  • A base built-in Criteria object that would come with additional functionalities. For instance, a pattern I like for sorting is using a query param "sort", in the following format: "sort=date,-id". This would sort by date in ascending order, then by id in descending order. The base Criteria could parse such strings.
  • Helper for parsing "expand". If you have a not-so-simple APIs, having the ability to asking other resources is often absolutely vital. For instance, if you display a list of users, and want to display their associated subscriptions, you could ask the following request: "/users?expand[]=subscription". Internally, you could read this and do an optimized query to load the subscriptions. However, expand can be nested, so if you want to load the subscriptions WITH the plan: "/users?expand[]=subscription.plan".

In view rendering template, I'd like to be able to do that:

if ($this->hasExpand('subscription')) {
    $data['subscription'] = $this->renderResource('user/subscription', ['subscription' => $user->getSubscription(), 'expand' => $this->reduceExpand('subscription');
}

In the previous example, if the expand is "subscription.plan", then hasExpand will return true, and reduceExpand on 'subscription' will return 'plan' (the part that comes after subscription).

Any other ideas? ping @Orkin @danizord

@bakura10 bakura10 added this to the 0.5.0 milestone Feb 6, 2015
@akaNightmare
Copy link

+1

@akaNightmare
Copy link

what the status of the issue?

@bakura10
Copy link
Member Author

None for now, I'm not doing programming those times :(.

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

No branches or pull requests

2 participants