|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Gregurco\Bundle\GuzzleBundleWssePlugin; |
| 4 | + |
| 5 | + |
| 6 | +use EightPoints\Bundle\GuzzleBundle\EightPointsGuzzleBundlePlugin; |
| 7 | +use Gregurco\Bundle\GuzzleBundleWssePlugin\DependencyInjection\GuzzleWsseExtension; |
| 8 | +use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
| 9 | +use Symfony\Component\HttpKernel\Bundle\Bundle; |
| 10 | +use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 11 | +use Symfony\Component\DependencyInjection\Definition; |
| 12 | +use Symfony\Component\ExpressionLanguage\Expression; |
| 13 | + |
| 14 | +class GuzzleBundleWssePlugin extends Bundle implements EightPointsGuzzleBundlePlugin |
| 15 | +{ |
| 16 | + /** |
| 17 | + * @param array $configs |
| 18 | + * @param ContainerBuilder $container |
| 19 | + */ |
| 20 | + public function load(array $configs, ContainerBuilder $container) |
| 21 | + { |
| 22 | + $extension = new GuzzleWsseExtension(); |
| 23 | + $extension->load($configs, $container); |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * @param array $config |
| 28 | + * @param ContainerBuilder $container |
| 29 | + * @param string $clientName |
| 30 | + * @param Definition $handler |
| 31 | + */ |
| 32 | + public function loadForClient(array $config, ContainerBuilder $container, string $clientName, Definition $handler) |
| 33 | + { |
| 34 | + if ($config['username'] && $config['password']) { |
| 35 | + $wsse = new Definition('%guzzle_bundle_wsse_plugin.middleware.wsse.class%'); |
| 36 | + $wsse->setArguments([$config['username'], $config['password'], $config['created_at']]); |
| 37 | + |
| 38 | + $wsseServiceName = sprintf('guzzle_bundle_wsse_plugin.middleware.wsse.%s', $clientName); |
| 39 | + |
| 40 | + $container->setDefinition($wsseServiceName, $wsse); |
| 41 | + |
| 42 | + $wsseExpression = new Expression(sprintf('service("%s").attach()', $wsseServiceName)); |
| 43 | + |
| 44 | + $handler->addMethodCall('push', [$wsseExpression]); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * @param ArrayNodeDefinition $pluginNode |
| 50 | + */ |
| 51 | + public function addConfiguration(ArrayNodeDefinition $pluginNode) |
| 52 | + { |
| 53 | + $pluginNode |
| 54 | + ->addDefaultsIfNotSet() |
| 55 | + ->children() |
| 56 | + ->scalarNode('username')->defaultNull()->end() |
| 57 | + ->scalarNode('password')->defaultNull()->end() |
| 58 | + ->scalarNode('created_at')->defaultNull()->end() |
| 59 | + ->end(); |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * @return string |
| 64 | + */ |
| 65 | + public function getPluginName() : string |
| 66 | + { |
| 67 | + return 'wsse'; |
| 68 | + } |
| 69 | +} |
0 commit comments