diff --git a/src/Bundle/ChillCalendarBundle/DependencyInjection/ChillCalendarExtension.php b/src/Bundle/ChillCalendarBundle/DependencyInjection/ChillCalendarExtension.php index 5aa8d8507..1e37a7ebc 100644 --- a/src/Bundle/ChillCalendarBundle/DependencyInjection/ChillCalendarExtension.php +++ b/src/Bundle/ChillCalendarBundle/DependencyInjection/ChillCalendarExtension.php @@ -47,6 +47,8 @@ class ChillCalendarExtension extends Extension implements PrependExtensionInterf } else { $container->setParameter('chill_calendar.short_messages', null); } + + $container->setParameter('chill_calendar.remote_calendar_dsn', $config['remote_calendar_dsn']); } public function prepend(ContainerBuilder $container) diff --git a/src/Bundle/ChillCalendarBundle/DependencyInjection/Configuration.php b/src/Bundle/ChillCalendarBundle/DependencyInjection/Configuration.php index a3e4ae391..e4ca96ca2 100644 --- a/src/Bundle/ChillCalendarBundle/DependencyInjection/Configuration.php +++ b/src/Bundle/ChillCalendarBundle/DependencyInjection/Configuration.php @@ -32,9 +32,10 @@ class Configuration implements ConfigurationInterface ->canBeDisabled() ->children()->end() ->end() // end for short_messages + ->scalarNode('remote_calendar_dsn')->defaultValue('null://null')->cannotBeEmpty()->end() ->arrayNode('remote_calendars_sync')->canBeEnabled() ->children() - ->arrayNode('microsoft_graph')->canBeEnabled() + ->arrayNode('microsoft_graph')->canBeEnabled()->setDeprecated('chill-project/chill-bundles', '4.7.0', 'The child node %node% at path %path% is deprecated: use remote_calendar_dsn instead, with a "msgraph://default" value') ->children() ->end() // end of machine_access_token ->end() // end of microsoft_graph children diff --git a/src/Bundle/ChillCalendarBundle/RemoteCalendar/DependencyInjection/RemoteCalendarCompilerPass.php b/src/Bundle/ChillCalendarBundle/RemoteCalendar/DependencyInjection/RemoteCalendarCompilerPass.php index c52fc2866..3fb82ac6a 100644 --- a/src/Bundle/ChillCalendarBundle/RemoteCalendar/DependencyInjection/RemoteCalendarCompilerPass.php +++ b/src/Bundle/ChillCalendarBundle/RemoteCalendar/DependencyInjection/RemoteCalendarCompilerPass.php @@ -35,25 +35,46 @@ use TheNetworg\OAuth2\Client\Provider\Azure; class RemoteCalendarCompilerPass implements CompilerPassInterface { + private const ZIMBRA_CONNECTOR = 'Chill\ZimbraBundle\Calendar\Connector\ZimbraConnector'; + + private const MS_GRAPH_SERVICES_TO_REMOVE = [ + MapAndSubscribeUserCalendarCommand::class, + AzureGrantAdminConsentAndAcquireToken::class, + RemoteCalendarConnectAzureController::class, + MachineTokenStorage::class, + MachineHttpClient::class, + MSGraphRemoteCalendarConnector::class, + MSUserAbsenceReaderInterface::class, + MSUserAbsenceSync::class, + ]; + public function process(ContainerBuilder $container) { - $config = $container->getParameter('chill_calendar'); + $config = $container->getParameter('chill_calendar.remote_calendar_dsn'); + if (true === $container->getParameter('chill_calendar')['remote_calendars_sync']['microsoft_graph']['enabled']) { + $dsn = 'msgraph://default'; + } else { + $dsn = $config; + } - if (true === $config['remote_calendars_sync']['microsoft_graph']['enabled']) { + $scheme = parse_url($dsn, PHP_URL_SCHEME); + + if ('msgraph' === $scheme) { $connector = MSGraphRemoteCalendarConnector::class; $container->setAlias(HttpClientInterface::class.' $machineHttpClient', MachineHttpClient::class); - } else { + } elseif ('zimbra+http' === $scheme || 'zimbra+https' === $scheme) { + $connector = self::ZIMBRA_CONNECTOR; + foreach (self::MS_GRAPH_SERVICES_TO_REMOVE as $serviceId) { + $container->removeDefinition($serviceId); + } + } elseif ('null' === $scheme) { $connector = NullRemoteCalendarConnector::class; - // remove services which cannot be loaded - $container->removeDefinition(MapAndSubscribeUserCalendarCommand::class); - $container->removeDefinition(AzureGrantAdminConsentAndAcquireToken::class); - $container->removeDefinition(RemoteCalendarConnectAzureController::class); - $container->removeDefinition(MachineTokenStorage::class); - $container->removeDefinition(MachineHttpClient::class); - $container->removeDefinition(MSGraphRemoteCalendarConnector::class); - $container->removeDefinition(MSUserAbsenceReaderInterface::class); - $container->removeDefinition(MSUserAbsenceSync::class); + foreach (self::MS_GRAPH_SERVICES_TO_REMOVE as $serviceId) { + $container->removeDefinition($serviceId); + } + } else { + throw new \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException('Unsupported remote calendar scheme: '.$scheme); } if (!$container->hasAlias(Azure::class) && $container->hasDefinition('knpu.oauth2.client.azure')) { @@ -62,7 +83,9 @@ class RemoteCalendarCompilerPass implements CompilerPassInterface foreach ([ NullRemoteCalendarConnector::class, - MSGraphRemoteCalendarConnector::class, ] as $serviceId) { + MSGraphRemoteCalendarConnector::class, + self::ZIMBRA_CONNECTOR, + ] as $serviceId) { if ($connector === $serviceId) { $container->getDefinition($serviceId) ->setDecoratedService(RemoteCalendarConnectorInterface::class);