From 62f0ba6898574be18fd7ec7e8e3ad9001b7e203c Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Sun, 27 Sep 2015 17:38:39 -0400 Subject: [PATCH] Adding a kernel that loads routes from itself --- .../FrameworkBundle/Kernel/MicroKernel.php | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernel.php diff --git a/src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernel.php b/src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernel.php new file mode 100644 index 0000000000000..876a07f7370f7 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernel.php @@ -0,0 +1,71 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\Kernel; + +use Symfony\Bundle\FrameworkBundle\Routing\RouteCollectionBuilder; +use Symfony\Component\Config\Loader\LoaderInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\HttpKernel\MicroKernel as BaseMicroKernel; +use Symfony\Component\Routing\Loader\RouteLoaderInterface; + +/** + * A kernel that adds some functionality that depends on FrameworkBundle. + * + * @author Ryan Weaver + */ +abstract class MicroKernel extends BaseMicroKernel implements RouteLoaderInterface +{ + /** + * Add or import routes into your application. + * + * $routes->import('config/routing.yml'); + * $routes->add('/admin', 'AppBundle:Admin:dashboard', 'admin_dashboard'); + * + * @param RouteCollectionBuilder $routes + */ + abstract protected function configureRoutes(RouteCollectionBuilder $routes); + + /** + * Creates a RouteCollectionBuilder for convenience and calls configureRoutes. + * + * @param LoaderInterface $loader + * + * @return \Symfony\Component\Routing\RouteCollection + */ + public function getRouteCollection(LoaderInterface $loader) + { + $routes = new RouteCollectionBuilder($loader); + + $this->configureRoutes($routes); + + return $routes->build(); + } + + /** + * Overridden to make the routing resource be the kernel. + * + * @param LoaderInterface $loader + */ + public function registerContainerConfiguration(LoaderInterface $loader) + { + $loader->load(function (ContainerBuilder $container) { + $container->prependExtensionConfig('framework', array( + 'router' => array( + 'resource' => 'kernel', + 'type' => 'service', + ), + )); + }); + + parent::registerContainerConfiguration($loader); + } +} pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy