DefaultLogoutSuccessHandler.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Security\Http\Logout;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\Security\Http\HttpUtils;
  13. use Symfony\Component\Security\Http\Logout\LogoutSuccessHandlerInterface;
  14. /**
  15. * Default logout success handler will redirect users to a configured path.
  16. *
  17. * @author Fabien Potencier <fabien@symfony.com>
  18. * @author Alexander <iam.asm89@gmail.com>
  19. */
  20. class DefaultLogoutSuccessHandler implements LogoutSuccessHandlerInterface
  21. {
  22. protected $httpUtils;
  23. protected $targetUrl;
  24. /**
  25. * @param HttpUtils $httpUtils
  26. * @param string $targetUrl
  27. */
  28. public function __construct(HttpUtils $httpUtils, $targetUrl = '/')
  29. {
  30. $this->httpUtils = $httpUtils;
  31. $this->targetUrl = $targetUrl;
  32. }
  33. /**
  34. * {@inheritDoc}
  35. */
  36. public function onLogoutSuccess(Request $request)
  37. {
  38. return $this->httpUtils->createRedirectResponse($request, $this->targetUrl);
  39. }
  40. }