refactor and rename classes

This commit is contained in:
Julien Fastré 2022-05-09 13:55:04 +02:00
parent 8abce5ab85
commit d570145385
21 changed files with 61 additions and 95 deletions

View File

@ -11,7 +11,7 @@ declare(strict_types=1);
namespace Chill\CalendarBundle;
use Chill\CalendarBundle\Synchro\DependencyInjection\RemoteCalendarCompilerPass;
use Chill\CalendarBundle\RemoteCalendar\DependencyInjection\RemoteCalendarCompilerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

View File

@ -11,7 +11,7 @@ declare(strict_types=1);
namespace Chill\CalendarBundle\Command;
use Chill\CalendarBundle\Synchro\Connector\MSGraph\MachineTokenStorage;
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\MachineTokenStorage;
use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;

View File

@ -11,7 +11,7 @@ declare(strict_types=1);
namespace Chill\CalendarBundle\Command;
use Chill\CalendarBundle\Synchro\Connector\MSGraph\MapCalendarToUser;
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\MapCalendarToUser;
use Chill\MainBundle\Repository\UserRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Command\Command;

View File

@ -13,8 +13,8 @@ namespace Chill\CalendarBundle\Controller;
use Chill\CalendarBundle\Entity\Calendar;
use Chill\CalendarBundle\Form\CalendarType;
use Chill\CalendarBundle\RemoteCalendar\Connector\RemoteCalendarConnectorInterface;
use Chill\CalendarBundle\Repository\CalendarRepository;
use Chill\CalendarBundle\Synchro\Connector\RemoteCalendarConnectorInterface;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Pagination\PaginatorFactory;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;

View File

@ -11,7 +11,7 @@ declare(strict_types=1);
namespace Chill\CalendarBundle\Controller;
use Chill\CalendarBundle\Synchro\Connector\MSGraph\MSGraphTokenStorage;
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\OnBehalfOfUserTokenStorage;
use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
use Symfony\Component\HttpFoundation\RedirectResponse;
@ -25,11 +25,11 @@ class RemoteCalendarConnectAzureController
{
private ClientRegistry $clientRegistry;
private MSGraphTokenStorage $MSGraphTokenStorage;
private OnBehalfOfUserTokenStorage $MSGraphTokenStorage;
public function __construct(
ClientRegistry $clientRegistry,
MSGraphTokenStorage $MSGraphTokenStorage
OnBehalfOfUserTokenStorage $MSGraphTokenStorage
) {
$this->clientRegistry = $clientRegistry;
$this->MSGraphTokenStorage = $MSGraphTokenStorage;

View File

@ -11,7 +11,7 @@ declare(strict_types=1);
namespace Chill\CalendarBundle\Controller;
use Chill\CalendarBundle\Synchro\Connector\RemoteCalendarConnectorInterface;
use Chill\CalendarBundle\RemoteCalendar\Connector\RemoteCalendarConnectorInterface;
use Chill\MainBundle\Entity\User;
use DateTimeImmutable;
use Symfony\Component\HttpFoundation\JsonResponse;

View File

@ -36,7 +36,7 @@ class ChillCalendarExtension extends Extension implements PrependExtensionInterf
$loader->load('services/fixtures.yml');
$loader->load('services/form.yml');
$loader->load('services/event.yml');
$loader->load('services/synchro.yaml');
$loader->load('services/remote_calendar.yaml');
$container->setParameter('chill_calendar', $config);
}

View File

@ -9,7 +9,7 @@
declare(strict_types=1);
namespace Chill\CalendarBundle\Synchro\Connector\MSGraph;
namespace Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph;
use League\OAuth2\Client\Tool\BearerAuthorizationTrait;
use LogicException;

View File

@ -9,7 +9,7 @@
declare(strict_types=1);
namespace Chill\CalendarBundle\Synchro\Connector\MSGraph;
namespace Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph;
use Chill\MainBundle\Redis\ChillRedis;
use League\OAuth2\Client\Token\AccessTokenInterface;

View File

@ -9,9 +9,9 @@
declare(strict_types=1);
namespace Chill\CalendarBundle\Synchro\Connector\MSGraph;
namespace Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph;
use Chill\CalendarBundle\Synchro\Connector\MSGraphRemoteCalendarConnector;
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraphRemoteCalendarConnector;
use Chill\MainBundle\Entity\User;
use Psr\Log\LoggerInterface;

View File

@ -9,7 +9,7 @@
declare(strict_types=1);
namespace Chill\CalendarBundle\Synchro\Connector\MSGraph;
namespace Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph;
use League\OAuth2\Client\Tool\BearerAuthorizationTrait;
use LogicException;
@ -17,18 +17,18 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;
use Symfony\Contracts\HttpClient\ResponseStreamInterface;
class UserHttpClient
class OnBehalfOfUserHttpClient
{
use BearerAuthorizationTrait;
private HttpClientInterface $decoratedClient;
private MSGraphTokenStorage $tokenStorage;
private OnBehalfOfUserTokenStorage $tokenStorage;
/**
* @param HttpClientInterface $decoratedClient
*/
public function __construct(MSGraphTokenStorage $tokenStorage, ?HttpClientInterface $decoratedClient = null)
public function __construct(OnBehalfOfUserTokenStorage $tokenStorage, ?HttpClientInterface $decoratedClient = null)
{
$this->decoratedClient = $decoratedClient ?? \Symfony\Component\HttpClient\HttpClient::create();
$this->tokenStorage = $tokenStorage;

View File

@ -9,14 +9,17 @@
declare(strict_types=1);
namespace Chill\CalendarBundle\Synchro\Connector\MSGraph;
namespace Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph;
use LogicException;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use TheNetworg\OAuth2\Client\Provider\Azure;
use TheNetworg\OAuth2\Client\Token\AccessToken;
class MSGraphTokenStorage
/**
* Store token obtained on behalf of a User.
*/
class OnBehalfOfUserTokenStorage
{
public const MS_GRAPH_ACCESS_TOKEN = 'msgraph_access_token';

View File

@ -9,12 +9,16 @@
declare(strict_types=1);
namespace Chill\CalendarBundle\Synchro\Connector\MSGraph;
namespace Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph;
use Chill\CalendarBundle\Synchro\Model\RemoteEvent;
use Chill\CalendarBundle\RemoteCalendar\Model\RemoteEvent;
use DateTimeImmutable;
use DateTimeZone;
/**
* Convert Chill Calendar event to Remote MS Graph event, and MS Graph
* event to RemoteEvent.
*/
class RemoteEventConverter
{
private const REMOTE_DATE_FORMAT = 'Y-m-d\TH:i:s.u0';

View File

@ -9,12 +9,12 @@
declare(strict_types=1);
namespace Chill\CalendarBundle\Synchro\Connector;
namespace Chill\CalendarBundle\RemoteCalendar\Connector;
use Chill\CalendarBundle\Synchro\Connector\MSGraph\MachineHttpClient;
use Chill\CalendarBundle\Synchro\Connector\MSGraph\MSGraphTokenStorage;
use Chill\CalendarBundle\Synchro\Connector\MSGraph\RemoteEventConverter;
use Chill\CalendarBundle\Synchro\Connector\MSGraph\UserHttpClient;
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\MachineHttpClient;
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\OnBehalfOfUserHttpClient;
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\OnBehalfOfUserTokenStorage;
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\RemoteEventConverter;
use Chill\MainBundle\Entity\User;
use DateTimeImmutable;
use Symfony\Component\HttpFoundation\RedirectResponse;
@ -27,18 +27,18 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
private RemoteEventConverter $remoteEventConverter;
private MSGraphTokenStorage $tokenStorage;
private OnBehalfOfUserTokenStorage $tokenStorage;
private UrlGeneratorInterface $urlGenerator;
private UserHttpClient $userHttpClient;
private OnBehalfOfUserHttpClient $userHttpClient;
public function __construct(
MachineHttpClient $machineHttpClient,
MSGraphTokenStorage $tokenStorage,
OnBehalfOfUserTokenStorage $tokenStorage,
OnBehalfOfUserHttpClient $userHttpClient,
RemoteEventConverter $remoteEventConverter,
UrlGeneratorInterface $urlGenerator,
UserHttpClient $userHttpClient
UrlGeneratorInterface $urlGenerator
) {
$this->machineHttpClient = $machineHttpClient;
$this->remoteEventConverter = $remoteEventConverter;

View File

@ -9,7 +9,7 @@
declare(strict_types=1);
namespace Chill\CalendarBundle\Synchro\Connector;
namespace Chill\CalendarBundle\RemoteCalendar\Connector;
use Chill\MainBundle\Entity\User;
use DateTimeImmutable;

View File

@ -9,9 +9,9 @@
declare(strict_types=1);
namespace Chill\CalendarBundle\Synchro\Connector;
namespace Chill\CalendarBundle\RemoteCalendar\Connector;
use Chill\CalendarBundle\Synchro\Model\RemoteEvent;
use Chill\CalendarBundle\RemoteCalendar\Model\RemoteEvent;
use Chill\MainBundle\Entity\User;
use DateTimeImmutable;
use Symfony\Component\HttpFoundation\Response;

View File

@ -9,11 +9,11 @@
declare(strict_types=1);
namespace Chill\CalendarBundle\Synchro\DependencyInjection;
namespace Chill\CalendarBundle\RemoteCalendar\DependencyInjection;
use Chill\CalendarBundle\Synchro\Connector\MSGraphRemoteCalendarConnector;
use Chill\CalendarBundle\Synchro\Connector\NullRemoteCalendarConnector;
use Chill\CalendarBundle\Synchro\Connector\RemoteCalendarConnectorInterface;
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraphRemoteCalendarConnector;
use Chill\CalendarBundle\RemoteCalendar\Connector\NullRemoteCalendarConnector;
use Chill\CalendarBundle\RemoteCalendar\Connector\RemoteCalendarConnectorInterface;
use RuntimeException;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

View File

@ -9,7 +9,7 @@
declare(strict_types=1);
namespace Chill\CalendarBundle\Synchro\Model;
namespace Chill\CalendarBundle\RemoteCalendar\Model;
use DateTimeImmutable;
use Symfony\Component\Serializer\Annotation as Serializer;

View File

@ -0,0 +1,15 @@
services:
_defaults:
autoconfigure: true
autowire: true
Chill\CalendarBundle\RemoteCalendar\Connector\RemoteCalendarConnectorInterface: ~
Chill\CalendarBundle\RemoteCalendar\Connector\NullRemoteCalendarConnector: ~
Chill\CalendarBundle\RemoteCalendar\Connector\MSGraphRemoteCalendarConnector: ~
Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\:
resource: '../../RemoteCalendar/Connector/MSGraph/'

View File

@ -1,15 +0,0 @@
services:
_defaults:
autoconfigure: true
autowire: true
Chill\CalendarBundle\Synchro\Connector\RemoteCalendarConnectorInterface: ~
Chill\CalendarBundle\Synchro\Connector\NullRemoteCalendarConnector: ~
Chill\CalendarBundle\Synchro\Connector\MSGraphRemoteCalendarConnector: ~
Chill\CalendarBundle\Synchro\Connector\MSGraph\:
resource: '../../Synchro/Connector/MSGraph/'

View File

@ -1,41 +0,0 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\CalendarBundle\Synchro\Connector\MSGraph;
use DateTimeImmutable;
use TheNetworg\OAuth2\Client\Provider\Azure;
class MSGraphClient
{
private MachineTokenStorage $machineTokenStorage;
private Azure $provider;
private MSGraphTokenStorage $tokenStorage;
/**
* @param mixed $calendar
*
* @return array as a json response
*/
public function listEventsForUserCalendar($calendar, DateTimeImmutable $startDate, DateTimeImmutable $endDate, ?int $start = null, ?int $limit = null): array
{
$from = $startDate->format(DateTimeImmutable::ATOM);
$to = $endDate->format(DateTimeImmutable::ATOM);
$response = $this->provider->getObjects("{$calendar}/calendar/calendarView?startDateTime={$from}&endDateTime={$end}");
dump($response);
return $response;
}
}