Skip to content

Commit 9770e46

Browse files
committed
Remove dependency to session service and use RequestStack instead of it to support Symfony 6
https://symfony.com/blog/new-in-symfony-5-3-session-service-deprecation
1 parent 0e4999a commit 9770e46

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/Resources/config/vatri_google_drive.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ services:
1515

1616
vatri_google_drive.api_service:
1717
class: Vatri\GoogleDriveBundle\Service\DriveApiService
18-
arguments: [ '@session', '@parameter_bag', '@vatri_google_drive.cookie_token_storage' ]
18+
arguments: [ '@request_stack', '@parameter_bag', '@vatri_google_drive.cookie_token_storage' ]
1919

2020
# Alias:
2121
Vatri\GoogleDriveBundle\Service\DriveApiService: '@vatri_google_drive.api_service'
@@ -26,5 +26,5 @@ services:
2626
autoconfigure: true
2727
arguments:
2828
$parameterBag: '@parameter_bag'
29-
$session: '@session'
29+
$session: '@request_stack'
3030
$driveApiService: '@vatri_google_drive.api_service'

src/Service/DriveApiService.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Symfony\Component\HttpFoundation\Session\SessionInterface;
77
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
88
use Symfony\Component\HttpFoundation\File\UploadedFile;
9+
use Symfony\Component\HttpFoundation\RequestStack;
910
use Vatri\GoogleDriveBundle\DriveServiceResponse;
1011

1112

@@ -33,9 +34,11 @@ class DriveApiService
3334
private $token_storage;
3435

3536

36-
public function __construct(SessionInterface $session, ParameterBagInterface $parameters, TokenStorageInterface $tokenStorage)
37+
public function __construct(RequestStack $requestStack, ParameterBagInterface $parameters, TokenStorageInterface $tokenStorage)
3738
{
38-
$this->session = $session;
39+
try {
40+
$this->session = $requestStack->getSession();
41+
} catch (\Exception $exception) {}
3942
$this->parameters = $parameters;
4043
$this->token_storage = $tokenStorage;
4144
}

0 commit comments

Comments
 (0)