mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
add null remote connector and basic interface
This commit is contained in:
parent
aecdfa6b12
commit
0212193940
@ -11,8 +11,16 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\CalendarBundle;
|
||||
|
||||
use Chill\CalendarBundle\Synchro\DependencyInjection\SynchroCompilerPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
|
||||
class ChillCalendarBundle extends Bundle
|
||||
{
|
||||
public function build(ContainerBuilder $container)
|
||||
{
|
||||
parent::build($container);
|
||||
|
||||
$container->addCompilerPass(new SynchroCompilerPass());
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ namespace Chill\CalendarBundle\Controller;
|
||||
use Chill\CalendarBundle\Entity\Calendar;
|
||||
use Chill\CalendarBundle\Form\CalendarType;
|
||||
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;
|
||||
@ -47,20 +48,24 @@ class CalendarController extends AbstractController
|
||||
|
||||
private CalendarRepository $calendarRepository;
|
||||
|
||||
private RemoteCalendarConnectorInterface $remoteCalendarConnector;
|
||||
|
||||
public function __construct(
|
||||
EventDispatcherInterface $eventDispatcher,
|
||||
AuthorizationHelper $authorizationHelper,
|
||||
CalendarRepository $calendarRepository,
|
||||
EventDispatcherInterface $eventDispatcher,
|
||||
LoggerInterface $logger,
|
||||
SerializerInterface $serializer,
|
||||
PaginatorFactory $paginator,
|
||||
CalendarRepository $calendarRepository
|
||||
RemoteCalendarConnectorInterface $remoteCalendarConnector,
|
||||
SerializerInterface $serializer
|
||||
) {
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
$this->authorizationHelper = $authorizationHelper;
|
||||
$this->logger = $logger;
|
||||
$this->serializer = $serializer;
|
||||
$this->paginator = $paginator;
|
||||
$this->calendarRepository = $calendarRepository;
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
$this->logger = $logger;
|
||||
$this->paginator = $paginator;
|
||||
$this->remoteCalendarConnector = $remoteCalendarConnector;
|
||||
$this->serializer = $serializer;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -183,27 +188,6 @@ class CalendarController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{_locale}/calendar/calendar/my", name="chill_calendar_calendar_list_my")
|
||||
*
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
public function myCalendar(Request $request): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted('ROLE_USER');
|
||||
|
||||
if (!$this->getUser() instanceof User) {
|
||||
throw new UnauthorizedHttpException('you are not an user');
|
||||
}
|
||||
|
||||
$view = '@ChillCalendar/Calendar/listByUser.html.twig';
|
||||
|
||||
return $this->render($view, [
|
||||
'user' => $this->getUser(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all Calendar entities.
|
||||
*
|
||||
@ -251,6 +235,28 @@ class CalendarController extends AbstractController
|
||||
throw new Exception('Unable to list actions.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{_locale}/calendar/calendar/my", name="chill_calendar_calendar_list_my")
|
||||
*/
|
||||
public function myCalendar(Request $request): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted('ROLE_USER');
|
||||
|
||||
if (!$this->getUser() instanceof User) {
|
||||
throw new UnauthorizedHttpException('you are not an user');
|
||||
}
|
||||
|
||||
if (!$this->remoteCalendarConnector->isReady()) {
|
||||
return $this->remoteCalendarConnector->getMakeReadyResponse();
|
||||
}
|
||||
|
||||
$view = '@ChillCalendar/Calendar/listByUser.html.twig';
|
||||
|
||||
return $this->render($view, [
|
||||
'user' => $this->getUser(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new calendar item.
|
||||
*
|
||||
|
@ -36,6 +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');
|
||||
}
|
||||
|
||||
public function prepend(ContainerBuilder $container)
|
||||
|
@ -0,0 +1,8 @@
|
||||
services:
|
||||
_defaults:
|
||||
autoconfigure: true
|
||||
autowire: true
|
||||
|
||||
Chill\CalendarBundle\Synchro\Connector\RemoteCalendarConnectorInterface: ~
|
||||
|
||||
Chill\CalendarBundle\Synchro\Connector\NullRemoteCalendarConnector: ~
|
@ -0,0 +1,28 @@
|
||||
<?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;
|
||||
|
||||
use LogicException;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class NullRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
{
|
||||
public function getMakeReadyResponse(): Response
|
||||
{
|
||||
throw new LogicException('As this connector is always ready, this method should not be called');
|
||||
}
|
||||
|
||||
public function isReady(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
<?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;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
interface RemoteCalendarConnectorInterface
|
||||
{
|
||||
/**
|
||||
* Return a response, more probably a RedirectResponse, where the user
|
||||
* will be able to fullfill requirements to prepare this connector and
|
||||
* make it ready.
|
||||
*/
|
||||
public function getMakeReadyResponse(): Response;
|
||||
|
||||
/**
|
||||
* Return true if the connector is ready to act as a proxy for reading
|
||||
* remote calendars.
|
||||
*/
|
||||
public function isReady(): bool;
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?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\DependencyInjection;
|
||||
|
||||
use Chill\CalendarBundle\Synchro\Connector\NullRemoteCalendarConnector;
|
||||
use Chill\CalendarBundle\Synchro\Connector\RemoteCalendarConnectorInterface;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
class SynchroCompilerPass implements CompilerPassInterface
|
||||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
$nullConnector = $container->getDefinition(NullRemoteCalendarConnector::class);
|
||||
$nullConnector->setDecoratedService(RemoteCalendarConnectorInterface::class);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user