Skip to content

[Routing] Documented the option to exclude patterns #12821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,8 @@ the common configuration using options when importing the routes.
# An imported route with an empty URL will become "/blog/"
# Uncomment this option to make that URL "/blog" instead
# trailing_slash_on_root: false
# you can optionally exclude some files/subdirectories when loading annotations
# exclude: '../src/Controller/{DebugEmailController}.php'

.. code-block:: xml

Expand All @@ -1187,11 +1189,13 @@ the common configuration using options when importing the routes.
<!--
the 'prefix' value is added to the beginning of all imported route URLs
the 'name-prefix' value is added to the beginning of all imported route names
the 'exclude' option defines the files or subdirectories ignored when loading annotations
-->
<import resource="../src/Controller/"
type="annotation"
prefix="/blog"
name-prefix="blog_">
name-prefix="blog_"
exclude="../src/Controller/{DebugEmailController}.php">
<!-- these requirements are added to all imported routes -->
<requirement key="_locale">en|es|fr</requirement>
</import>
Expand All @@ -1211,6 +1215,8 @@ the common configuration using options when importing the routes.
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;

return function (RoutingConfigurator $routes) {
// use the optional fifth argument of import() to exclude some files
// or subdirectories when loading annotations
$routes->import('../src/Controller/', 'annotation')
// this is added to the beginning of all imported route URLs
->prefix('/blog')
Expand All @@ -1224,6 +1230,11 @@ the common configuration using options when importing the routes.
;
};

.. versionadded:: 4.4

The option to exclude some files or subdirectories when loading annotations
was introduced in Symfony 4.4.

In this example, the route of the ``index()`` action will be called ``blog_index``
and its URL will be ``/blog/``. The route of the ``show()`` action will be called
``blog_show`` and its URL will be ``/blog/{_locale}/posts/{slug}``. Both routes
Expand Down