2021-02-05 14:47:54 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace RetailCrm\ServiceBundle\DependencyInjection;
|
|
|
|
|
|
|
|
use RetailCrm\ServiceBundle\ArgumentResolver\CallbackValueResolver;
|
|
|
|
use RetailCrm\ServiceBundle\ArgumentResolver\ClientValueResolver;
|
2021-03-31 11:00:48 +03:00
|
|
|
use RetailCrm\ServiceBundle\Messenger\MessageHandler;
|
2021-02-05 14:47:54 +03:00
|
|
|
use RetailCrm\ServiceBundle\Response\ErrorJsonResponseFactory;
|
|
|
|
use RetailCrm\ServiceBundle\Security\CallbackClientAuthenticator;
|
|
|
|
use RetailCrm\ServiceBundle\Security\FrontApiClientAuthenticator;
|
2021-02-17 09:31:36 +03:00
|
|
|
use RetailCrm\ServiceBundle\Serializer\JMSSerializerAdapter;
|
|
|
|
use RetailCrm\ServiceBundle\Serializer\SymfonySerializerAdapter;
|
2021-02-05 14:47:54 +03:00
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
|
|
use Symfony\Component\DependencyInjection\Extension\Extension;
|
2021-02-17 09:31:36 +03:00
|
|
|
use Symfony\Component\DependencyInjection\Reference;
|
2021-02-05 14:47:54 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class RetailCrmServiceExtension
|
|
|
|
*
|
|
|
|
* @package RetailCrm\ServiceBundle\DependencyInjection
|
|
|
|
*/
|
|
|
|
class RetailCrmServiceExtension extends Extension
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @param array $configs
|
|
|
|
* @param ContainerBuilder $container
|
|
|
|
*/
|
|
|
|
public function load(array $configs, ContainerBuilder $container): void
|
|
|
|
{
|
|
|
|
$configuration = $this->getConfiguration($configs, $container);
|
|
|
|
$config = $this->processConfiguration($configuration, $configs);
|
|
|
|
|
|
|
|
$container->setParameter(
|
2021-02-17 09:31:36 +03:00
|
|
|
'retail_crm_service.request_schema.callback.supports',
|
|
|
|
$config['request_schema']['callback']['supports']
|
2021-02-05 14:47:54 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
$container->setParameter(
|
2021-02-17 09:31:36 +03:00
|
|
|
'retail_crm_service.request_schema.client.supports',
|
|
|
|
$config['request_schema']['client']['supports']
|
2021-02-05 14:47:54 +03:00
|
|
|
);
|
|
|
|
|
2021-02-17 09:31:36 +03:00
|
|
|
$container->setParameter(
|
|
|
|
'retail_crm_service.request_schema.callback.serializer',
|
|
|
|
$config['request_schema']['callback']['serializer']
|
|
|
|
);
|
|
|
|
|
|
|
|
$container->setParameter(
|
|
|
|
'retail_crm_service.request_schema.client.serializer',
|
|
|
|
$config['request_schema']['client']['serializer']
|
|
|
|
);
|
|
|
|
|
2021-03-31 11:00:48 +03:00
|
|
|
$container->setParameter(
|
|
|
|
'retail_crm_service.messenger.message_handler',
|
|
|
|
$config['messenger']['message_handler']
|
|
|
|
);
|
|
|
|
|
|
|
|
if (isset($config['messenger']['process_timeout'])) {
|
|
|
|
$container->setParameter(
|
|
|
|
'retail_crm_service.messenger.process_timeout',
|
|
|
|
$config['messenger']['process_timeout']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-02-17 09:31:36 +03:00
|
|
|
$container
|
|
|
|
->register(SymfonySerializerAdapter::class)
|
|
|
|
->setAutowired(true);
|
|
|
|
$container->setAlias('retail_crm_service.symfony_serializer.adapter', SymfonySerializerAdapter::class);
|
|
|
|
|
|
|
|
$container
|
|
|
|
->register(JMSSerializerAdapter::class)
|
|
|
|
->setAutowired(true);
|
|
|
|
$container->setAlias('retail_crm_service.jms_serializer.adapter', JMSSerializerAdapter::class);
|
|
|
|
|
2021-02-05 14:47:54 +03:00
|
|
|
$container
|
|
|
|
->register(CallbackValueResolver::class)
|
2021-02-17 09:31:36 +03:00
|
|
|
->setArguments([
|
|
|
|
new Reference($container->getParameter('retail_crm_service.request_schema.callback.serializer')),
|
|
|
|
new Reference('validator'),
|
|
|
|
$container->getParameter('retail_crm_service.request_schema.callback.supports')
|
|
|
|
])
|
2021-02-05 14:47:54 +03:00
|
|
|
->addTag('controller.argument_value_resolver', ['priority' => 50])
|
|
|
|
->setAutowired(true);
|
|
|
|
|
|
|
|
$container
|
|
|
|
->register(ClientValueResolver::class)
|
2021-02-17 09:31:36 +03:00
|
|
|
->setArguments([
|
|
|
|
new Reference($container->getParameter('retail_crm_service.request_schema.client.serializer')),
|
|
|
|
new Reference('validator'),
|
|
|
|
$container->getParameter('retail_crm_service.request_schema.client.supports')
|
|
|
|
])
|
2021-02-05 14:47:54 +03:00
|
|
|
->addTag('controller.argument_value_resolver', ['priority' => 50])
|
|
|
|
->setAutowired(true);
|
|
|
|
|
|
|
|
$container
|
|
|
|
->register(ErrorJsonResponseFactory::class)
|
|
|
|
->setAutowired(true);
|
|
|
|
|
|
|
|
$container
|
|
|
|
->register(CallbackClientAuthenticator::class)
|
|
|
|
->setAutowired(true);
|
|
|
|
|
|
|
|
$container
|
|
|
|
->register(FrontApiClientAuthenticator::class)
|
|
|
|
->setAutowired(true);
|
2021-03-31 11:00:48 +03:00
|
|
|
|
|
|
|
$container
|
|
|
|
->register(MessageHandler\SimpleConsoleRunner::class)
|
|
|
|
->setAutowired(true);
|
|
|
|
$container->setAlias('simple_console_runner', MessageHandler\SimpleConsoleRunner::class);
|
|
|
|
|
|
|
|
$timeout = $container->hasParameter('retail_crm_service.messenger.process_timeout')
|
|
|
|
? $container->getParameter('retail_crm_service.messenger.process_timeout')
|
|
|
|
: null;
|
|
|
|
|
|
|
|
$container
|
|
|
|
->register(MessageHandler\InNewProcessRunner::class)
|
|
|
|
->setArgument('$timeout', $timeout)
|
|
|
|
->setAutowired(true);
|
|
|
|
$container->setAlias('in_new_process_runner', MessageHandler\InNewProcessRunner::class);
|
|
|
|
|
|
|
|
$container
|
|
|
|
->register(MessageHandler::class)
|
|
|
|
->addTag('messenger.message_handler')
|
|
|
|
->setArguments([
|
|
|
|
new Reference($container->getParameter('retail_crm_service.messenger.message_handler'))
|
|
|
|
])
|
|
|
|
->setAutowired(true);
|
2021-02-05 14:47:54 +03:00
|
|
|
}
|
|
|
|
}
|