diff --git a/bundles/routing/configuration.rst b/bundles/routing/configuration.rst index fec81d71..0970ce61 100644 --- a/bundles/routing/configuration.rst +++ b/bundles/routing/configuration.rst @@ -28,6 +28,7 @@ To add the ``DynamicRouter``, use the following configuration: .. code-block:: yaml + # app/config/config.yml cmf_routing: chain: routers_by_id: @@ -36,6 +37,7 @@ To add the ``DynamicRouter``, use the following configuration: .. code-block:: xml + @@ -50,14 +52,15 @@ To add the ``DynamicRouter``, use the following configuration: .. code-block:: php - $container->loadFromExtension('cmf_routing', array( - 'chain' => array( - 'routers_by_id' => array( + // app/config/config.php + $container->loadFromExtension('cmf_routing', [ + 'chain' => [ + 'routers_by_id' => [ 'cmf_routing.dynamic_router' => 200, 'router.default' => 100, - ), - ), - )); + ], + ], + ]); .. tip:: @@ -79,12 +82,14 @@ default router, because :ref:`no other routers were set @@ -98,11 +103,12 @@ default router, because :ref:`no other routers were set loadFromExtension('cmf_routing', array( - 'chain' => array( + // app/config/config.php + $container->loadFromExtension('cmf_routing', [ + 'chain' => [ 'replace_symfony_router' => true, - ), - )); + ], + ]); .. _reference-config-routing-dynamic: @@ -123,10 +129,9 @@ generic_controller **type**: ``string`` **default**: ``null`` -The controller to use when the route enhancers only determined the template but -no explicit controller. The value is the name of a controller using either the -``AcmeDemoBundle::Page::index`` or ``acme_demo.controller.page:indexAction`` -notation. +This configuration specifies the controller that is used when the route +enhancers define a template but no explicit controller. It accepts any valid +Symfony controller reference. If the :doc:`CoreBundle <../core/introduction>` and :doc:`ContentBundle <../content/introduction>` are registered, this @@ -139,7 +144,7 @@ defaults to ``cmf_content.controller:indexAction``. The default controller to use if none of the enhancers found a controller. The value is the name of a controller using either the -``AcmeDemoBundle::Page::index`` or ``acme_demo.controller.page:indexAction`` +``AppBundle::Page::index`` or ``app.page_controller:indexAction`` notation. ``controllers_by_type`` @@ -155,20 +160,21 @@ type: .. code-block:: yaml + # app/config/config.yml cmf_routing: dynamic: controllers_by_type: - editable: acme_main.controller:editableAction + editable: AppBundle:Cms:editable .. code-block:: xml - + - acme_main.controller:editableAction + AppBundle:Cms:editable @@ -176,13 +182,14 @@ type: .. code-block:: php - $container->loadFromExtension('cmf_routing', array( - 'dynamic' => array( - 'controllers_by_type' => array( - 'editable' => 'acme_main.controller:editableAction', - ), - ), - )); + // app/config/config.php + $container->loadFromExtension('cmf_routing', [ + 'dynamic' => [ + 'controllers_by_type' => [ + 'editable' => 'AppBundle:Cms:editable', + ], + ], + ]); controllers_by_class .................... @@ -203,6 +210,7 @@ choose this controller to handle the request. .. code-block:: yaml + # app/config/config.yml cmf_routing: dynamic: controllers_by_class: @@ -210,6 +218,7 @@ choose this controller to handle the request. .. code-block:: xml + @@ -226,10 +235,13 @@ choose this controller to handle the request. .. code-block:: php - $container->loadFromExtension('cmf_routing', array( - 'dynamic' => array( - 'controllers_by_class' => array( - 'Symfony\Cmf\Bundle\ContentBundle\Document\StaticContent' => 'cmf_content.controller:indexAction', + // app/config/config.php + use Symfony\Cmf\Bundle\ContentBundle\Document\StaticContent; + + $container->loadFromExtension('cmf_routing', [ + 'dynamic' => [ + 'controllers_by_class' => [ + StaticContent::class => 'cmf_content.controller:indexAction', ), ), )); @@ -255,6 +267,7 @@ setting is set as controller. .. code-block:: yaml + # app/config/config.yml cmf_routing: dynamic: templates_by_class: @@ -262,9 +275,9 @@ setting is set as controller. .. code-block:: xml + - loadFromExtension('cmf_routing', array( - 'dynamic' => array( - 'templates_by_class' => array( - 'Symfony\Cmf\Bundle\ContentBundle\Document\StaticContent' => 'CmfContentBundle:StaticContent:index.html.twig', + // app/config/config.php + use Symfony\Cmf\Bundle\ContentBundle\Document\StaticContent; + + $container->loadFromExtension('cmf_routing', [ + 'dynamic' => [ + 'templates_by_class' => [ + StaticContent::class => 'CmfContentBundle:StaticContent:index.html.twig', ), ), )); @@ -349,24 +365,25 @@ disables the limit entirely. .. code-block:: php - $container->loadFromExtension('cmf_routing', array( - 'dynamic' => array( - 'persistence' => array( - 'phpcr' => array( + # app/config/config.php + $container->loadFromExtension('cmf_routing', [ + 'dynamic' => [ + 'persistence' => [ + 'phpcr' => [ 'enabled' => false, 'manager_name' => null, - 'route_basepaths' => array( + 'route_basepaths' => [ '/cms/routes', '/cms/simple', - ) + ], 'content_basepath' => '/cms/content', 'admin_basepath' => '/cms/routes', 'use_sonata_admin' => 'auto', 'enable_initializer' => true, - ), - ), - ), - )); + ], + ], + ], + ]); enabled ******* @@ -470,7 +487,7 @@ If ``true``, the ORM is included in the service container. The name of the Doctrine Manager to use. ``route_class`` -**************** +*************** **type**: ``string`` **default**: ``'Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Orm\Route'`` @@ -511,20 +528,21 @@ priority. .. code-block:: yaml + # app/config/config.yml cmf_routing: dynamic: route_filters_by_id: - acme_main.routing.foo_filter: 100 + app.routing_filter: 100 .. code-block:: xml - + - 100 + 100 @@ -532,13 +550,14 @@ priority. .. code-block:: php - $container->loadFromExtension('cmf_routing', array( - 'dynamic' => array( - 'route_filters_by_id' => array( - 'acme_main.routing.foo_filter' => 100, - ), - ), - )); + // app/config/config.php + $container->loadFromExtension('cmf_routing', [ + 'dynamic' => [ + 'route_filters_by_id' => [ + 'app.routing_filter' => 100, + ], + ], + ]); ``content_repository_service_id`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -568,7 +587,7 @@ service. ``locales`` ~~~~~~~~~~~ -**type**: ``array`` **default**: ``array()`` +**type**: ``array`` **default**: ``[]`` To enable multi-language, set the valid locales in this option. diff --git a/bundles/routing/dynamic.rst b/bundles/routing/dynamic.rst index a8b19f15..43c500d0 100644 --- a/bundles/routing/dynamic.rst +++ b/bundles/routing/dynamic.rst @@ -68,21 +68,21 @@ routers. .. code-block:: php // app/config/config.php - $container->loadFromExtension('cmf_routing', array( - 'chain' => array( - 'routers_by_id' => array( + $container->loadFromExtension('cmf_routing', [ + 'chain' => [ + 'routers_by_id' => [ 'router.default' => 200, 'cmf_routing.dynamic_router' => 100, - ), - ), - 'dynamic' => array( - 'persistence' => array( - 'phpcr' => array( + ], + ], + 'dynamic' => [ + 'persistence' => [ + 'phpcr' => [ 'enabled' => true, - ), - ), - ), - )); + ], + ], + ], + ]); When there is no configuration or ``cmf_routing.dynamic.enabled`` is set to ``false``, the dynamic router services will not be loaded at all, allowing @@ -106,7 +106,8 @@ not need any logic. A custom controller action can look like this:: - namespace Acme\DemoBundle\Controller; + // src/AppBundle/Controller/ContentController.php + namespace AppBundle\Controller; use Symfony\Component\HttpFoundation\Response; use Symfony\Bundle\FrameworkBundle\Controller\Controller; @@ -128,10 +129,10 @@ A custom controller action can look like this:: // ... do things with $contentDocument and gather other information $customValue = 42; - return $this->render('AcmeDemoBundle:Content:demo.html.twig', array( + return $this->render('content/demo.html.twig', [ 'cmfMainContent' => $contentDocument, 'custom_parameter' => $customValue, - )); + ]); } } @@ -240,7 +241,7 @@ All routes are located under a configured root path, for example $route->setName('projects'); // set explicit controller (both service and Bundle:Name:action syntax work) - $route->setDefault('_controller', 'sandbox_main.controller:specialAction'); + $route->setDefault('_controller', 'app.controller:specialAction'); The above example should probably be done as a route configured in a Symfony configuration file, unless the end user is supposed to change the URL @@ -380,19 +381,19 @@ base path. .. code-block:: php // app/config/config.php - $container->loadFromExtension('cmf_routing', array( - 'dynamic' => array( - 'persistence' => array( - 'phpcr' => array( + $container->loadFromExtension('cmf_routing', [ + 'dynamic' => [ + 'persistence' => [ + 'phpcr' => [ // use true/false to force using / not using sonata admin 'use_sonata_admin' => 'auto', // used with Sonata Admin to manage content; defaults to %cmf_core.basepath%/content 'content_basepath' => null, - ), - ), - ), - )); + ], + ], + ], + ]); .. _bundle-routing-entity: @@ -508,9 +509,9 @@ an empty route name and tries to find a content implementing the .. code-block:: html+php - generate(null, [ 'content_id' => '/cms/content/my-content', - )) ?>"> + ]) ?>"> Home @@ -573,13 +574,16 @@ documents. You need to configure the route enhancer for this interface: .. code-block:: php - $container->loadFromExtension('cmf_routing', array( - 'dynamic' => array( - 'controllers_by_class' => array( - 'Symfony\Cmf\Bundle\Routing\RedirectRouteInterface' => 'cmf_routing.redirect_controller:redirectAction', - ), - ), - )); + // app/config/config.php + use Symfony\Cmf\Bundle\Routing\RedirectRouteInterface; + + $container->loadFromExtension('cmf_routing', [ + 'dynamic' => [ + 'controllers_by_class' => [ + RedirectRouteInterface::class => 'cmf_routing.redirect_controller:redirectAction', + ], + ], + ]); RouteReferrersInterface Sonata Admin Extension ---------------------------------------------- @@ -605,25 +609,29 @@ configuration in the ``sonata_admin`` section of your project configuration: .. code-block:: xml - - - - Symfony\Cmf\Component\Routing\RouteReferrersInterface - - + + + + + Symfony\Cmf\Component\Routing\RouteReferrersInterface + + + .. code-block:: php // app/config/config.php - $container->loadFromExtension('sonata_admin', array( - 'extensions' => array( - 'cmf_routing.admin_extension.route_referrers' => array( - 'implements' => array( - 'Symfony\Cmf\Component\Routing\RouteReferrersInterface', - ), - ), - ), - )); + use Symfony\Cmf\Bundle\Routing\RedirectRouteInterface; + + $container->loadFromExtension('sonata_admin', [ + 'extensions' => [ + 'cmf_routing.admin_extension.route_referrers' => [ + 'implements' => [ + RouteReferrersInterface::class, + ], + ], + ], + ]); See the `Sonata Admin extension documentation`_ for more information. @@ -654,6 +662,7 @@ configuration in the ``sonata_admin`` section of your project configuration: .. code-block:: xml + @@ -665,18 +674,21 @@ configuration in the ``sonata_admin`` section of your project configuration: .. code-block:: php // app/config/config.php - $container->loadFromExtension('sonata_admin', array( - 'extensions' => array( - 'cmf_routing.admin_extension.frontend_link' => array( - 'implements' => array( - 'Symfony\Cmf\Component\Routing\RouteReferrersReadInterface', - ), - 'extends' => array( - 'Symfony\Component\Routing\Route', - ), - ), - ), - )); + use Symfony\Cmf\Component\Routing\RouteReferrersReadInterface; + use Symfony\Component\Routing\Route; + + $container->loadFromExtension('sonata_admin', [ + 'extensions' => [ + 'cmf_routing.admin_extension.frontend_link' => [ + 'implements' => [ + RouteReferrersReadInterface::class, + ], + 'extends' => [ + Route::class, + ], + ], + ], + ]); See the `Sonata Admin extension documentation`_ for more information. diff --git a/bundles/routing/dynamic_customize.rst b/bundles/routing/dynamic_customize.rst index 5f11dc6e..c485ce64 100644 --- a/bundles/routing/dynamic_customize.rst +++ b/bundles/routing/dynamic_customize.rst @@ -52,6 +52,7 @@ is executed. .. code-block:: yaml + # app/config/services.yml services: app.routing.simple_enhancer: class: AppBundle\Routing\Enhancer\SimpleEnhancer @@ -60,6 +61,7 @@ is executed. .. code-block:: xml + addTag('dynamic_router_route_enhancer', array( + $definition = new Definition(SimpleEnhancer::class); + $definition->addTag('dynamic_router_route_enhancer', [ 'priority' => 10, - )); + ]); $container->setDefinition('app.routing.simple_enhancer', $definition); @@ -102,8 +106,8 @@ following class provides a simple solution using an ODM Repository. .. code-block:: php - // src/Acme/DemoBundle/Repository/RouteProvider.php - namespace Acme\DemoBundle\Repository; + // src/AppBundle/Repository/RouteProvider.php + namespace AppBundle\Repository; use Doctrine\ODM\PHPCR\DocumentRepository; use Symfony\Cmf\Component\Routing\RouteProviderInterface; @@ -118,9 +122,9 @@ following class provides a simple solution using an ODM Repository. public function findManyByUrl($url) { // for simplicity we retrieve one route - $document = $this->findOneBy(array( + $document = $this->findOneBy([ 'url' => $url, - )); + ]); $pattern = $document->getUrl(); // e.g. "/this/is/a/url" @@ -128,9 +132,9 @@ following class provides a simple solution using an ODM Repository. // create a new Route and set our document as // a default (so that we can retrieve it from the request) - $route = new SymfonyRoute($pattern, array( + $route = new SymfonyRoute($pattern, [ 'document' => $document, - )); + ]); // add the route to the RouteCollection using // a unique ID as the key. @@ -142,19 +146,19 @@ following class provides a simple solution using an ODM Repository. /** * This method is used to generate URLs, e.g. {{ path('foobar') }}. */ - public function getRouteByName($name, $params = array()) + public function getRouteByName($name, $params = []) { - $document = $this->findOneBy(array( + $document = $this->findOneBy([ 'name' => $name, - )); + ]); if (!$document) { throw new RouteNotFoundException("No route found for name '$name'"); } - $route = new SymfonyRoute($document->getUrl(), array( + $route = new SymfonyRoute($document->getUrl(), [ 'document' => $document, - )); + ]); return $route; } @@ -182,7 +186,7 @@ configuration as follows: # app/config/config.yml cmf_routing: dynamic: - route_provider_service_id: acme_demo.provider.endpoint + route_provider_service_id: app.route_provider .. code-block:: xml @@ -190,20 +194,20 @@ configuration as follows: - + .. code-block:: php // app/config/config.php - $container->loadFromExtension('cmf_routing', array( - 'dynamic' => array( - 'route_provider_service_id' => 'acme_demo.provider.endpoint', - ), - )); + $container->loadFromExtension('cmf_routing', [ + 'dynamic' => [ + 'route_provider_service_id' => 'app.route_provider', + ], + ]); -Where ``acme_demo.provider.endpoint`` is the service ID of your route +Where ``app.route_provider`` is the service ID of your route provider. See `Creating and configuring services in the container`_ for information on creating custom services. @@ -226,7 +230,7 @@ yourself and configure that service: # app/config/config.yml cmf_routing: dynamic: - url_generator: routing.my_generator + url_generator: app.my_url_generator .. code-block:: xml @@ -234,18 +238,18 @@ yourself and configure that service: - + .. code-block:: php // app/config/config.php - $container->loadFromExtension('cmf_routing', array( - 'dynamic' => array( - 'url_generator' => 'routing.my_generator', - ), - )); + $container->loadFromExtension('cmf_routing', [ + 'dynamic' => [ + 'url_generator' => 'app.my_url_generator', + ], + ]); .. _bundle-routing-route-defaults-validator: diff --git a/bundles/routing/introduction.rst b/bundles/routing/introduction.rst index 415554d8..5e88c9ff 100644 --- a/bundles/routing/introduction.rst +++ b/bundles/routing/introduction.rst @@ -64,24 +64,28 @@ will look like this .. code-block:: yaml + # app/config/services.yml services: - acme_core.my_router: - class: "%my_namespace.my_router_class%" + app.my_router: + class: AppBundle\Routing\MyRouter tags: - { name: router, priority: 300 } .. code-block:: xml - + + - .. code-block:: php + # app/config/services.php + use AppBundle\Routing\MyRouter; + $container - ->register('acme_core.my_router', '%acme_core.my_router') - ->addTag('router', array('priority' => 300)) + ->register('app.my_router', MyRouter::class) + ->addTag('router', ['priority' => 300]) ; See also official Symfony2 `documentation for DependencyInjection tags`_