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 = '[email protected]';

    public function __construct(SessionInterface $session) {
        $client = new \Google_Client();

I have the feeling that having the session as a dependency is not a 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\$ Commented Jan 21, 2021 at 0:50


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.