/**
  * {@inheritDoc}
  */
 public function process(ContainerBuilder $container)
 {
     if (!$this->integrationExtension->isVarTagValidatorEnabled()) {
         if (count($container->findTaggedServiceIds('validator.var_tag.constraint_factory')) > 0) {
             throw new \RuntimeException('Could not compile var tag validator constraint factory, because system is not enabled.');
         }
         return;
     }
     $registryDefinition = $container->getDefinition('validator.var_tag.constraint_factory_registry');
     foreach ($container->findTaggedServiceIds('validator.var_tag.constraint_factory') as $id => $tags) {
         $factoryDefinition = $container->getDefinition($id);
         $class = $factoryDefinition->getClass();
         try {
             $class = $container->getParameterBag()->resolveValue($class);
             $refClass = new \ReflectionClass($class);
             $requiredInterface = 'FivePercent\\Component\\VarTagValidator\\Constraint\\ConstraintFactoryInterface';
             if (!$refClass->implementsInterface($requiredInterface)) {
                 throw new \RuntimeException(sprintf('The var tag constraint factory should implement "%s" interface.', $requiredInterface));
             }
             foreach ($tags as $attributes) {
                 if (empty($attributes['type'])) {
                     throw new \RuntimeException('Missing attribute "type".');
                 }
                 $registryDefinition->addMethodCall('addConstraintFactory', [$attributes['type'], new Reference($id)]);
             }
         } catch (\Exception $e) {
             throw new \RuntimeException(sprintf('Could not compile var tag validator constraint factory with service id "%s".', $id));
         }
     }
 }
 /**
  * {@inheritDoc}
  */
 public function process(ContainerBuilder $container)
 {
     if (!$this->integrationExtension->isNotifierEnabled()) {
         if (count($container->findTaggedServiceIds('notifier.sender.strategy')) > 0) {
             throw new \RuntimeException('Could not compile notifier sender strategy, because system is not enabled.');
         }
         return;
     }
     $strategyManagerDefinition = $container->findDefinition('notifier.sender_strategy_manager');
     foreach ($container->findTaggedServiceIds('notifier.sender.strategy') as $id => $tags) {
         $definition = $container->getDefinition($id);
         $class = $definition->getClass();
         try {
             $class = $container->getParameterBag()->resolveValue($class);
             $refClass = new \ReflectionClass($class);
             $requiredInterface = 'FivePercent\\Component\\Notifier\\SenderStrategy\\SenderStrategyInterface';
             if (!$refClass->implementsInterface($requiredInterface)) {
                 throw new \RuntimeException(sprintf('The notifier sender strategy should implement "%s" interface.', $requiredInterface));
             }
             foreach ($tags as $index => $attributes) {
                 if (empty($attributes['key'])) {
                     throw new \RuntimeException(sprintf('The "key" parameter for tag with index "%d" must be a specified.', $index));
                 }
                 $strategyManagerDefinition->addMethodCall('addStrategy', [$attributes['key'], new Reference($id)]);
             }
         } catch (\Exception $e) {
             throw new \RuntimeException(sprintf('Could not compile notifier sender strategy with service id "%s".', $id), 0, $e);
         }
     }
 }
 /**
  * {@inheritDoc}
  */
 public function process(ContainerBuilder $container)
 {
     if (!$this->integrationExtension->isModelTransformerEnabled()) {
         if (count($container->findTaggedServiceIds('model_transformer'))) {
             throw new \RuntimeException('Could not compile model transformer, because system is not enabled.');
         }
         return;
     }
     $transformerManagerDefinition = $container->getDefinition('model_transformer');
     foreach ($container->findTaggedServiceIds('model_transformer') as $id => $tags) {
         $attributes = $this->fixAttributes($tags);
         $attributes += ['priority' => 0];
         $definition = $container->getDefinition($id);
         $class = $definition->getClass();
         try {
             $class = $container->getParameterBag()->resolveValue($class);
             $refClass = new \ReflectionClass($class);
             $requiredInterface = 'FivePercent\\Component\\ModelTransformer\\ModelTransformerInterface';
             if (!$refClass->implementsInterface($requiredInterface)) {
                 throw new \RuntimeException(sprintf('The model transformer should implement "%s" interface.', $requiredInterface));
             }
         } catch (\Exception $e) {
             throw new \RuntimeException(sprintf('Could not compile model transformer with service id "%s".', $id), 0, $e);
         }
         $transformerManagerDefinition->addMethodCall('addTransformer', [new Reference($id), $attributes['priority']]);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function process(ContainerBuilder $container)
 {
     if (!$this->integrationExtension->isObjectSecurityEnabled()) {
         if (count($container->findTaggedServiceIds('object_security.rule_voter')) > 0) {
             throw new \RuntimeException('Could not compile security rule voter, because system is not enabled.');
         }
         return;
     }
     $chainVoterDefinition = $container->getDefinition('object_security.rule_voter');
     foreach ($container->findTaggedServiceIds('object_security.rule_voter') as $id => $attributes) {
         $definition = $container->getDefinition($id);
         $class = $definition->getClass();
         try {
             $class = $container->getParameterBag()->resolveValue($class);
             $refClass = new \ReflectionClass($class);
             $requiredInterface = 'FivePercent\\Component\\ObjectSecurity\\Rule\\Voter\\RuleVoterInterface';
             if (!$refClass->implementsInterface($requiredInterface)) {
                 throw new \RuntimeException(sprintf('The rule voter must be implemented of "%s" interface.', $requiredInterface));
             }
         } catch (\Exception $e) {
             throw new \RuntimeException(sprintf('Could not compile security rule voter with service id "%s".', $id), 0, $e);
         }
         $chainVoterDefinition->addMethodCall('addVoter', [new Reference($id)]);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function process(ContainerBuilder $container)
 {
     if (!$this->integrationExtension->isEnabledCheckerEnabled()) {
         if (count($container->findTaggedServiceIds('enabled_checker')) > 0) {
             throw new \RuntimeException('Could not compile enabled checker, because system is not enabled.');
         }
         return;
     }
     if ($container->hasDefinition('enabled_checker.checker_registry')) {
         $debugRegistry = $container->getDefinition('enabled_checker.checker_registry');
     }
     $chainCheckerDefinition = $container->getDefinition('enabled_checker.checker_chain');
     foreach ($container->findTaggedServiceIds('enabled_checker') as $id => $tags) {
         $attributes = $this->fixAttributes($tags);
         $attributes += ['priority' => 0];
         $checkerDefinition = $container->getDefinition($id);
         $class = $checkerDefinition->getClass();
         try {
             $class = $container->getParameterBag()->resolveValue($class);
             $refClass = new \ReflectionClass($class);
             $requiredInterface = 'FivePercent\\Component\\EnabledChecker\\Checker\\CheckerInterface';
             if (!$refClass->implementsInterface($requiredInterface)) {
                 throw new \RuntimeException(sprintf('The enabled checker should implement "%s" interface.', $requiredInterface));
             }
         } catch (\Exception $e) {
             throw new \RuntimeException(sprintf('Could not compile enabled checker with service id "%s".', $id), 0, $e);
         }
         $chainCheckerDefinition->addMethodCall('addChecker', [new Reference($id), $attributes['priority']]);
         if (isset($debugRegistry)) {
             $debugRegistry->addMethodCall('addChecker', [$id, $class, $attributes['priority']]);
         }
     }
 }
 /**
  * {@inheritDoc}
  */
 public function process(ContainerBuilder $container)
 {
     if (!$this->integrationExtension->isTransactionalAutoGenerateProxy()) {
         // Transactional system or auto generate proxy is disabled
         return;
     }
     $transactionalId = $this->integrationExtension->getTransactionalService();
     // Validate transactional service
     $transactionalDefinition = $container->getDefinition($transactionalId);
     $class = $transactionalDefinition->getClass();
     try {
         $class = $container->getParameterBag()->resolveValue($class);
         $refClass = new \ReflectionClass($class);
         $requiredInterface = 'FivePercent\\Component\\Transactional\\TransactionalInterface';
         if (!$refClass->implementsInterface($requiredInterface)) {
             throw new \RuntimeException(sprintf('The transactional service with class "%s" should implement %s.', $class, $requiredInterface));
         }
     } catch (\Exception $e) {
         throw new \RuntimeException(sprintf('The transactional service with id "%s" is invalid.', $transactionalId), 0, $e);
     }
     // Get all services
     $serviceIds = $container->getServiceIds();
     $directory = $container->getParameter('kernel.cache_dir') . '/transactional';
     foreach ($serviceIds as $serviceId) {
         if ($container->hasAlias($serviceId)) {
             // Not check in alias.
             continue;
         }
         $serviceDefinition = $container->getDefinition($serviceId);
         if ($serviceDefinition->isAbstract()) {
             // Not check in abstract service.
             continue;
         }
         $class = $serviceDefinition->getClass();
         $class = $container->getParameterBag()->resolveValue($class);
         if (!$class) {
             continue;
         }
         try {
             $proxyCodeGenerator = new ProxyFileGenerator($directory, $class);
         } catch (\ReflectionException $e) {
             $container->getCompiler()->addLogMessage(sprintf('%s Error with create proxy code generator for class "%s". Maybe class not found?', get_class($this), $class));
             continue;
         }
         if ($proxyCodeGenerator->needGenerate()) {
             // Generate proxy file
             $filePath = $proxyCodeGenerator->generate();
             $serviceDefinition->setClass($proxyCodeGenerator->getProxyClassName());
             // Add "__setTransactional" method call for set transactional layer
             $methodCalls = $serviceDefinition->getMethodCalls();
             array_unshift($methodCalls, ['___setTransactional', [new Reference($transactionalId)]]);
             $serviceDefinition->setMethodCalls($methodCalls);
             // Add resource for control cache
             $container->addResource(new FileResource($filePath));
             $realClassReflection = new \ReflectionClass($class);
             $container->addResource(new FileResource($realClassReflection->getFileName()));
         }
     }
 }
 /**
  * {@inheritDoc}
  */
 public function process(ContainerBuilder $container)
 {
     if (!$this->integrationExtension->isParameterConverterEnabled()) {
         if (count($container->findTaggedServiceIds('converter.parameter')) > 0) {
             throw new \RuntimeException('Could not compile parameter converter, because system is not enabled.');
         }
         return;
     }
     $converterManagerDefinition = $container->getDefinition('converter.parameter');
     $converterByGroups = ['default' => []];
     foreach ($container->findTaggedServiceIds('converter.parameter') as $id => $tags) {
         $converterDefinition = $container->getDefinition($id);
         $class = $converterDefinition->getClass();
         try {
             $class = $container->getParameterBag()->resolveValue($class);
             $refClass = new \ReflectionClass($class);
             $requiredInterface = 'FivePercent\\Component\\Converter\\Parameter\\ParameterConverterInterface';
             if (!$refClass->implementsInterface($requiredInterface)) {
                 throw new \RuntimeException(sprintf('The parameter converter should implement "%s" interface.', $requiredInterface));
             }
             if (count($tags) == 1) {
                 // Get first tag and check "group" parameter.
                 $attributes = $tags[0];
                 if (empty($attributes['group'])) {
                     $converterByGroups['default'][$id] = $converterDefinition;
                     continue;
                 }
             }
             foreach ($tags as $index => $attributes) {
                 if (empty($attributes['group'])) {
                     throw new \RuntimeException(sprintf('The attribute "group" is required if you many "converter.parameter" tag name. ' . 'Index tag: "%d".', $index));
                 }
                 if (!isset($converterByGroups[$attributes['group']])) {
                     $converterByGroups[$attributes['group']] = [];
                 }
                 $converterByGroups[$attributes['group']][$id] = $converterDefinition;
             }
         } catch (\Exception $e) {
             throw new \RuntimeException(sprintf('Could not compile parameter converter with service id "%s".', $id), 0, $e);
         }
     }
     foreach ($converterByGroups as $groupName => $converters) {
         // Create a chain converter for group
         $chainConverter = new DefinitionDecorator('converter.parameter.chain.abstract');
         $chainConverterId = 'converter.parameter.chain.' . $groupName;
         $container->setDefinition($chainConverterId, $chainConverter);
         foreach ($converters as $id => $converter) {
             $chainConverter->addMethodCall('addConverter', [new Reference($id)]);
         }
         $converterManagerDefinition->addMethodCall('setConverter', [new Reference($chainConverterId), $groupName]);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function process(ContainerBuilder $container)
 {
     if (!$this->integrationExtension->isVarTagReplaceSfValidator()) {
         return;
     }
     // @todo: add control validator API version
     // Rename ID for "validator" service
     $sfValidator = $container->getDefinition('validator');
     $container->setDefinition('validator.symfony', $sfValidator);
     $container->removeDefinition('validator');
     $coreValidator = new Definition('FivePercent\\Bundle\\IntegrationBundle\\VarTagValidator\\Validator');
     $coreValidator->setArguments([new Reference('validator.symfony'), new Reference('validator.var_tag')]);
     $container->setDefinition('validator', $coreValidator);
     $container->getDefinition('validator.var_tag')->replaceArgument(0, new Reference('validator.symfony'));
 }
 /**
  * {@inheritDoc}
  */
 public function process(ContainerBuilder $container)
 {
     if (!$this->integrationExtension->isNotifierEnabled() || !$this->integrationExtension->isNotifierReplaceSfEventDispatcher()) {
         return;
     }
     $dispatcherServiceId = 'event_dispatcher';
     while ($container->hasAlias($dispatcherServiceId)) {
         $dispatcherServiceId = $container->getAlias($dispatcherServiceId);
     }
     $dispatcherDefinition = $container->getDefinition($dispatcherServiceId);
     $dispatcherDefinition->setPublic(false);
     $container->removeDefinition($dispatcherServiceId);
     $container->setDefinition('event_dispatcher.symfony', $dispatcherDefinition);
     $notifierDispatcherDefinition = $container->getDefinition('event_dispatcher.notifier_proxy');
     $notifierDispatcherDefinition->replaceArgument(0, new Reference('event_dispatcher.symfony'));
     $notifierDispatcherDefinition->replaceArgument(2, $this->integrationExtension->getNotifierEventNamesForDisableNotification());
     $notifierDispatcherDefinition->setAbstract(false);
     $container->setAlias('event_dispatcher', 'event_dispatcher.notifier_proxy');
 }