Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Create RoutesDelegator when creating a new module #57

Open
geerteltink opened this issue Feb 15, 2018 · 1 comment
Open

Create RoutesDelegator when creating a new module #57

geerteltink opened this issue Feb 15, 2018 · 1 comment

Comments

@geerteltink
Copy link
Member

geerteltink commented Feb 15, 2018

As requested by @adamculp

I've grown accustomed to using a RoutesDelegator.php in my v2 Expressive projects, and specified it as follows in the ConfigProvider.php

public function getDependencies()
    {
        return [
            'delegators' => [
                \Zend\Expressive\Application::class => [
                    RoutesDelegator::class,
                ],
            ],
            'invokables' => [
            ],
            'factories'  => [
            ],
        ];
    }

When creating an Expressive driven modular application it makes module specific routes easier to maintain. (Not sure of the implications for a flat application.)

What are the thoughts of including this in the skeleton starting with v3?

So, other than adding the 'delegators' key to the ConfigProvider.php as part of the getDependencies() return, we could add the RouteDelegator.php with something like:

namespace App;

use App\Handler;
use Psr\Container\ContainerInterface;
use Zend\Expressive\Application;

class RoutesDelegator
{
    /**
     * @param ContainerInterface $container
     * @param string $serviceName Name of the service being created.
     * @param callable $callback Creates and returns the service.
     * @return Application
     */
    public function __invoke(ContainerInterface $container, $serviceName, callable $callback)
    {
        /** @var $app Application */
        $app = $callback();

        // Setup routes:
        $app->get('/', Handler\HomePageHandler::class, 'home');
        $app->get('/api/ping', Handler\PingHandler::class, 'api.ping');

        return $app;
    }
}

Thoughts?

For details and brief discussion see zendframework/zend-expressive-skeleton#223

@weierophinney
Copy link
Member

This repository has been closed and moved to mezzio/mezzio-tooling; a new issue has been opened at mezzio/mezzio-tooling#2.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants