-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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:: | ||
|
||
.. 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``:: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe: "[...] in your security configuration." There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we could use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call, I much prefer |
||
} | ||
} | ||
|
||
Next, create your own ``ExceptionListener``:: | ||
Finally, create your own ``ExceptionListener``:: | ||
|
||
// src/AppBundle/Security/Firewall/ExceptionListener.php | ||
namespace AppBundle\Security\Firewall; | ||
|
There was a problem hiding this comment.
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 [...]
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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 :)