My app interacts with Google Calendar. This Service wraps Google_Service_Calendar
:
<?php
declare(strict_types=1);
namespace App\Service;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
class GoogleCalendarService extends \Google_Service_Calendar
{
public const CALENDAR_ID = '[email protected]';
public function __construct(SessionInterface $session) {
$client = new \Google_Client();
$client->setAccessToken($session->get('google_access_token'));
parent::__construct($client);
}
}
I have the feeling that having the session as a dependency is not good practice. For a user of that service, it is absolutely not clear that the access token needs to be set in the session.
I could probably add some Exceptions for the case that it is not set, but I wonder whether there is a better way?
$session
be an optional parameter? if not, then under what conditions would an exception be warranted? \$\endgroup\$