chris-kruining / zf3-extensions
this is an expansion on the TreeRouteStack class that the zendframework/zend-router provides
Installs: 483
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 0
Type:routestack
Requires
- php: >=7.4
- chris-kruining/utilities: master
- laminas/laminas-mvc: ^3
- laminas/laminas-router: ^3
This package is auto-updated.
Last update: 2023-09-27 18:01:36 UTC
README
this is an extension of certain zend-framework 3 packages to enable me to do certain things
Instalation
$ composer require chris-kruining/zf3-filterablerouter
Configuration of filterable routes
return [ ... 'router' => [ 'router_class' => \CPB\Extensions\Zend\Router\FilterableTreeRouteStack::class, 'route_error_callback' => [ 'controller' => \Your\Own\Controller::class, ], 'routes' => [ 'sale' => [ 'type'=> 'Segment', 'filter' => <CALLABLE>, 'options'=> [ 'route' => '/sale[/:id]', 'constraints' => [ 'id' => '\d+' ], 'defaults' => [ 'controller' => \Your\Own\Controller::class, 'id' => 0, ], ], 'may_terminate' => false, 'child_routes' => [ 'discover' => [ 'type' => 'Method', 'options' => [ 'verb' => 'options,head', 'defaults' => [ 'action' => 'list', ], ], ], 'read' => [ 'type' => 'Method', 'options' => [ 'verb' => 'get', 'defaults' => [ 'action' => 'read', ], ], ], 'create' => [ 'type' => 'Method', 'options' => [ 'verb' => 'post', 'defaults' => [ 'action' => 'create', ], ], ], ], ], ] ], ... ];
To configure this zend extension all you need to do is
- set the
'router_class'
to\CPB\Extensions\Zend\Router\FilterableTreeRouteStack::class
. - supply an array to
'route_error_callback'
, this array needs at least a controller key-value, the second key you can apply is 'action' this value defaults to'error'
. - each route now has an extra config key besides
'type'
and'options'
you can now also supply'filter' => <CALLABLE>
, where<CALLABLE>
is a callable type (i.e.\Closure
,[class, method]
,'function'
)