src/Charcoal/App/Route/RouteManager.php
private function setupTemplate($routeIdent, $templateConfig)
    {
        $routePattern = isset($templateConfig['route'])
            ? $templateConfig['route']
            : '/'.ltrim($routeIdent, '/');

        $templateConfig['route'] = $routePattern;

        $methods = isset($templateConfig['methods'])
            ? $templateConfig['methods']
            : [ 'GET' ];

        $routeHandler = $this->app->map(
            $methods,
            $routePattern,
            function (
                RequestInterface $request,
                ResponseInterface $response,
                array $args = []
            ) use (
                $routeIdent,
                $templateConfig
            ) {
                if (!isset($templateConfig['ident'])) {
                    $templateConfig['ident'] = ltrim($routeIdent, '/');
                }

                $this['logger']->debug(
                    sprintf('Loaded template route: %s', $templateConfig['ident']),
                    $templateConfig
                );

                if (!isset($templateConfig['template_data'])) {
                    $templateConfig['template_data'] = [];
                }

                if (count($args)) {
                    $templateConfig['template_data'] = array_merge(
                        $templateConfig['template_data'],
                        $args
                    );
                }

                $defaultController = $this['route/controller/template/class'];
                $routeController   = isset($templateConfig['route_controller'])
                    ? $templateConfig['route_controller']
                    : $defaultController;

                $routeFactory = $this['route/factory'];
                $routeFactory->setDefaultClass($defaultController);

                $route = $routeFactory->create($routeController, [
                    'config' => $templateConfig,
                    'logger' => $this['logger']
                ]);

                return $route($this, $request, $response);
            }
        );

        if (isset($templateConfig['ident'])) {
            $routeHandler->setName($templateConfig['ident']);
        }

        return $routeHandler;
    }
private function setupTemplate($routeIdent, $templateConfig)
    {
        $routePattern = isset($templateConfig['route'])
            ? $templateConfig['route']
            : '/'.ltrim($routeIdent, '/');

        $templateConfig['route'] = $routePattern;

        $methods = isset($templateConfig['methods'])
            ? $templateConfig['methods']
            : [ 'GET' ];

        $routeHandler = $this->app->map(
            $methods,
            $routePattern,
            function (
                RequestInterface $request,
                ResponseInterface $response,
                array $args = []
            ) use (
                $routeIdent,
                $templateConfig
            ) {
                if (!isset($templateConfig['ident'])) {
                    $templateConfig['ident'] = ltrim($routeIdent, '/');
                }

                $this['logger']->debug(
                    sprintf('Loaded template route: %s', $templateConfig['ident']),
                    $templateConfig
                );

                if (!isset($templateConfig['template_data'])) {
                    $templateConfig['template_data'] = [];
                }

                if (count($args)) {
                    $templateConfig['template_data'] = array_merge(
                        $templateConfig['template_data'],
                        $args
                    );
                }

                $defaultController = $this['route/controller/template/class'];
                $routeController   = isset($templateConfig['route_controller'])
                    ? $templateConfig['route_controller']
                    : $defaultController;

                $routeFactory = $this['route/factory'];
                $routeFactory->setDefaultClass($defaultController);

                $route = $routeFactory->create($routeController, [
                    'config' => $templateConfig,
                    'logger' => $this['logger']
                ]);

                return $route($this, $request, $response);
            }
        );

        if (isset($templateConfig['ident'])) {
            $routeHandler->setName($templateConfig['ident']);
        }

        return $routeHandler;
    }
private function setupTemplate ( $ routeIdent , $ templateConfig ) { $ routePattern = isset ( $ templateConfig [ 'route' ] ) ? $ templateConfig [ 'route' ] : '/' . ltrim ( $ routeIdent , '/' ) ; $ templateConfig [ 'route' ] = $ routePattern ; $ methods = isset ( $ templateConfig [ 'methods' ] ) ? $ templateConfig [ 'methods' ] : [ 'GET' ] ; $ routeHandler = $ this -> app -> map ( $ methods , $ routePattern , function ( RequestInterface $ request , ResponseInterface $ response , array $ args = [ ] ) use ( $ routeIdent , $ templateConfig ) { if ( ! isset ( $ templateConfig [ 'ident' ] ) ) { $ templateConfig [ 'ident' ] = ltrim ( $ routeIdent , '/' ) ; } $ this [ 'logger' ] -> debug ( sprintf ( 'Loaded template route: %s' , $ templateConfig [ 'ident' ] ) , $ templateConfig ) ; if ( ! isset ( $ templateConfig [ 'template_data' ] ) ) { $ templateConfig [ 'template_data' ] = [ ] ; } if ( count ( $ args ) ) { $ templateConfig [ 'template_data' ] = array_merge ( $ templateConfig [ 'template_data' ] , $ args ) ; } $ defaultController = $ this [ 'route/controller/template/class' ] ; $ routeController = isset ( $ templateConfig [ 'route_controller' ] ) ? $ templateConfig [ 'route_controller' ] : $ defaultController ; $ routeFactory = $ this [ 'route/factory' ] ; $ routeFactory -> setDefaultClass ( $ defaultController ) ; $ route = $ routeFactory -> create ( $ routeController , [ 'config' => $ templateConfig , 'logger' => $ this [ 'logger' ] ] ) ; return $ route ( $ this , $ request , $ response ) ; } ) ; if ( isset ( $ templateConfig [ 'ident' ] ) ) { $ routeHandler -> setName ( $ templateConfig [ 'ident' ] ) ; } return $ routeHandler ; }
Add template route.

Typically for a GET request, the route will render a template.

@param  string             $routeIdent     The template's route identifier.
@param  array|\ArrayAccess $templateConfig The template's config for the route.
@return \Slim\Interfaces\RouteInterface
Add template route .