mezzio / mezzio-hal

Hypertext Application Language implementation for PHP and PSR-7

Home Page:https://docs.mezzio.dev/mezzio-hal/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Extend `RouteBasedCollectionStrategy`

weierophinney opened this issue · comments

I am trying to modify the default fields which appear in a collection response. In particular I'm filtering and paginating my collection and, beside _total_items I would like to have also other fields like _total_items_without_filters and _total_items_with filters_but_without_pagination.

The fact is that inside RouteBasedCollectionStrategy, the creation of the resource happens in the private method extractIterator which is called by the private method extractCollection, which requires also the presence of the method extractPaginator.

All of this said, to add a new field to the resource I must extends the RouteBasedCollectionStrategy class, copy and paste all the above mentioned methods, just to edit the line $data = ['_total_items' => $count];

It would be nice if just the creation of the $data could be exposed, at least in a protected method, so that modifying it could become easier


Originally posted by @marcosh at zendframework/zend-expressive-hal#47