phramework / jsonapi

jsonapi implementation for phramework
https://phramework.github.io/jsonapi/
Apache License 2.0
4 stars 2 forks source link

Abstract directive definition #38

Closed nohponex closed 7 years ago

nohponex commented 8 years ago

As a directive we define

Our goal is remove argument order restrictions on resource model get and getById calls allowing

Proposal is to have an interface class named IDirective each of the above MUST implemented.

get method signature MUST change to:

function get(IDirective ...$directives)

An execution example:

$users = Users::get(
    new Sort('name'),
    new Page()
);

Internally in get method value of given directive if any can be found like this:

$page = array_filter(
    $directives,
    function ($directive) {
        return get_class($directive) === Page::class;
    }
) ?? null; // or it can be get default instead of null 

NOTES: