mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
refactor and rename classes
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
<?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\RemoteCalendar\DependencyInjection;
|
||||
|
||||
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;
|
||||
use TheNetworg\OAuth2\Client\Provider\Azure;
|
||||
|
||||
class RemoteCalendarCompilerPass implements CompilerPassInterface
|
||||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
$config = $container->getParameter('chill_calendar');
|
||||
$connector = null;
|
||||
|
||||
if (!$config['remote_calendars_sync']['enabled']) {
|
||||
$connector = NullRemoteCalendarConnector::class;
|
||||
} else {
|
||||
if ($config['remote_calendars_sync']['microsoft_graph']['enabled']) {
|
||||
$connector = MSGraphRemoteCalendarConnector::class;
|
||||
|
||||
if (!$container->hasAlias(Azure::class)) {
|
||||
$container->setAlias(Azure::class, 'knpu.oauth2.provider.azure');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (null === $connector) {
|
||||
throw new RuntimeException('Could not configure remote calendar');
|
||||
}
|
||||
|
||||
foreach ([
|
||||
NullRemoteCalendarConnector::class,
|
||||
MSGraphRemoteCalendarConnector::class, ] as $serviceId) {
|
||||
if ($connector === $serviceId) {
|
||||
$container->getDefinition($serviceId)
|
||||
->setDecoratedService(RemoteCalendarConnectorInterface::class);
|
||||
} else {
|
||||
// keep the container lighter by removing definitions
|
||||
$container->removeDefinition($serviceId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user