zendframework / zend-expressive

PSR-15 middleware in minutes!
BSD 3-Clause "New" or "Revised" License
711 stars 197 forks source link

Zend router - child routes #336

Closed vaclavvanik closed 8 years ago

vaclavvanik commented 8 years ago

Hi, is there any way how to configure expressive router to use zf2 router's child routes?

weierophinney commented 8 years ago

Currently, no, though I think @DASPRiD was working on a solution.

The reason is this: zend-router is the only router we've run across that supports such a feature, and adapting other routers to support it was going to be hugely difficult, and complicate adding middleware to a large degree. As such, the RouterInterface targets the most common featureset common across routing implementations.

You can, of course, slipstream in your own routing middleware to allow it, however.

vbogoev commented 8 years ago

Any progress? I'll use zend-expressive for big project and I'll need child routes for sure...

harikt commented 8 years ago

Hi @vbogoev ,

I have not integrated zend-router, but as zend-router is integrated to expressive, in that case you can first instantiate the router and make / load the necessary changes to make that happen.

But if you are looking at the config/autoload/routes.global.php then probably there is no way I guess.

The same concept can be applied to Aura.Route attaching groups. But it is not the way zend-mvc-router did. Keeping the link in case you want to look into it https://github.com/auraphp/Aura.Router/tree/2.x#attaching-route-groups .

tasmaniski commented 8 years ago

I guess there will be no support for this feature?

michaelmoussa commented 8 years ago

There are no plans to implement this officially right now, but we could look at contributions for it.

On Tue, Oct 25, 2016 at 9:40 AM Alex notifications@github.com wrote:

I guess there will be no support for this feature?

— You are receiving this because you are subscribed to this thread.

Reply to this email directly, view it on GitHub https://github.com/zendframework/zend-expressive/issues/336#issuecomment-256037368, or mute the thread https://github.com/notifications/unsubscribe-auth/AALOGTlgBevea-3WkTcSagDypcMDIgUQks5q3gbTgaJpZM4IM8vV .

geerteltink commented 7 years ago

I knew zend-router supports it but I didn't know FastRoute and Aura.Router supported it in some way as well.

How hard would it be to implement this? I'm not thinking about actual using the child routes and groups of the specific routers since they seem to differ too much. I was thinking about doing it the FastRoute way and transform the child routes to normal single routes while they are being added. So just prefix a child route with its parents path. Could it be really that simple or am I missing something?

$app->addGroup('/blog', function (Application $app) {
    $app->route('/', Action\BlogIndexAction::class, ['GET'], 'blog');
    $app->route('/feed.xml', Action\BlogXmlFeedAction::class, ['GET'], 'feed');
    $app->route('/{id:[0-9a-zA-Z\-]+}', Action\BlogPostAction::class, ['GET'], 'blog.post');
});

Would translate to:

$app->route('/blog', Action\BlogIndexAction::class, ['GET'], 'blog');
$app->route('/blog/feed.xml', Action\BlogXmlFeedAction::class, ['GET'], 'feed');
$app->route('/blog/{id:[0-9a-zA-Z\-]+}', Action\BlogPostAction::class, ['GET'], 'blog.post');
tasmaniski commented 7 years ago

In my case it's not only in naming URLs.

For eg. at Admin panel I want to check the whole group instead of single route. Of course I can extract route name. In my case would be admin.post, admin.category, admin.comments ... And than to have my custom convention to explode route name by dot and than to check if user have permission for "admin" group.

so, it would be much clearer if there is a grouping routes.

geerteltink commented 7 years ago

@tasmaniski Checking the group is not possible. At least not with FastRoute. If you add a group, FastRoute internally translates all child routes into single routes. So internally the complete grouping does not do what you want it to do.

Checking the route name or add route options ('_security' => 'admin') might work for you.