3
\$\begingroup\$

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 = '123example@group.calendar.google.com';

    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?

\$\endgroup\$

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.