My app interacts with Google Calendar. This Service wraps Google_Service_Calendar:


namespace App\Service;

use Symfony\Component\HttpFoundation\Session\SessionInterface;

class GoogleCalendarService extends \Google_Service_Calendar
    public const CALENDAR_ID = '123example@group.calendar.google.com';

    public function __construct(SessionInterface $session) {
        $client = new \Google_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?

  • \$\begingroup\$ should $session be an optional parameter? if not, then under what conditions would an exception be warranted? \$\endgroup\$ Jan 21 '21 at 0:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.