Skip to content

Remove use of deprecated security.exception_listener.class parameter #7898

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

Closed
wants to merge 5 commits into from
Closed
Changes from 3 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
60 changes: 33 additions & 27 deletions security/target_path.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,42 @@ the user is redirected back to a page which the browser cannot render.
To get around this behavior, you would simply need to extend the ``ExceptionListener``
class and override the default method named ``setTargetPath()``.

First, override the ``security.exception_listener.class`` parameter in your
configuration file. This can be done from your main configuration file (in
``app/config``) or from a configuration file being imported from a bundle:
First, add a ``CompilerPass`` which you will use to override the ``ExceptionListener`` class::
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[...] add a compiler pass which [...]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and I would write "to replace" instead of "to override"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used override because that's the terminology from here: https://symfony.com/doc/current/bundles/override.html
But happy to change it :)


.. configuration-block::
// src/AppBundle/AppBundle.php
namespace AppBundle;

use AppBundle\DependencyInjection\Compiler\ExceptionListenerPass;

.. code-block:: yaml

# app/config/services.yml
parameters:
# ...
security.exception_listener.class: AppBundle\Security\Firewall\ExceptionListener

.. code-block:: xml

<!-- app/config/services.xml -->
<parameters>
<!-- ... -->
<parameter key="security.exception_listener.class">AppBundle\Security\Firewall\ExceptionListener</parameter>
</parameters>

.. code-block:: php

// app/config/services.php
use AppBundle\Security\Firewall\ExceptionListener;

// ...
$container->setParameter('security.exception_listener.class', ExceptionListener::class);
class AppBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
$container->addCompilerPass(new ExceptionListenerPass());
}
}

Next, create the ``ExceptionListenerPass`` to replace the definition of ``ExceptionListener``.
Make sure you use the name of the firewall you have configured in ``app/config``::
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe: "[...] in your security configuration."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That does sound better, I'll change it.


// src/AppBundle/DependencyInjection/Compiler/ExceptionListenerPass.php
namespace AppBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use AppBundle\Security\Firewall\ExceptionListener;

class ExceptionListenerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
// Use the name of your firewall as suffix e.g. 'secured_area'
$definition = $container->getDefinition('security.exception_listener.secured_area');
$definition->setClass('AppBundle\Security\Firewall\ExceptionListener');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could use the class constant here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, I much prefer class constants too.

}
}

Next, create your own ``ExceptionListener``::
Finally, create your own ``ExceptionListener``::

// src/AppBundle/Security/Firewall/ExceptionListener.php
namespace AppBundle\Security\Firewall;
Expand Down