chris-kruining/zf3-extensions

此包已被 废弃 且不再维护。未建议替代包。

这是基于zendframework/zend-router提供的TreeRouteStack类的一个扩展

1.2.8 2021-12-13 14:43 UTC

README

这是对某些zend-framework 3包的扩展,以便我能够完成某些事情

安装

$ composer require chris-kruining/zf3-filterablerouter

可过滤路由的配置

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',
                            ],
                        ],
                    ],
                ],
            ],
        ]
    ],
    ...
];

要配置此zend扩展,您只需执行以下操作:

  • 'router_class' 设置为 \CPB\Extensions\Zend\Router\FilterableTreeRouteStack::class
  • 'route_error_callback' 提供一个数组,此数组至少需要一个控制器键值对,第二个键可以是 'action',此值默认为 'error'
  • 每个路由现在除了 'type''options' 之外,还有一个额外的配置键,您现在还可以提供 'filter' => <CALLABLE>,其中 <CALLABLE> 是可调用类型(例如 \Closure[class, method]'function'