1414
1515use BeSimple \SoapCommon \Cache ;
1616
17+ use BeSimple \SoapCommon \SoapOptions \SoapOptions ;
18+ use Carpages \Core \Entity \ContactPhone ;
1719use Symfony \Component \Config \Definition \Processor ;
1820use Symfony \Component \Config \FileLocator ;
1921use Symfony \Component \DependencyInjection \ContainerBuilder ;
@@ -41,6 +43,7 @@ public function load(array $configs, ContainerBuilder $container)
4143 $ loader = new XmlFileLoader ($ container , new FileLocator (__DIR__ .'/../Resources/config ' ));
4244
4345 $ loader ->load ('request.xml ' );
46+ $ loader ->load ('soap.xml ' );
4447
4548 $ loader ->load ('loaders.xml ' );
4649 $ loader ->load ('converters.xml ' );
@@ -53,8 +56,8 @@ public function load(array $configs, ContainerBuilder $container)
5356
5457 $ this ->registerCacheConfiguration ($ config ['cache ' ], $ container , $ loader );
5558
56- if (! empty ($ config ['clients ' ])) {
57- $ this ->registerClientConfiguration ($ config[ ' clients ' ] , $ container , $ loader );
59+ if ( ! empty ($ config ['clients ' ])) {
60+ $ this ->registerClientConfiguration ($ config , $ container , $ loader );
5861 }
5962
6063 $ container ->setParameter ('besimple.soap.definition.dumper.options.stylesheet ' , $ config ['wsdl_dumper ' ]['stylesheet ' ]);
@@ -69,11 +72,9 @@ public function load(array $configs, ContainerBuilder $container)
6972
7073 private function registerCacheConfiguration (array $ config , ContainerBuilder $ container , XmlFileLoader $ loader )
7174 {
72- $ loader ->load ('soap.xml ' );
73-
7475 $ config ['type ' ] = $ this ->getCacheType ($ config ['type ' ]);
7576
76- foreach (array ('type ' , 'lifetime ' , ' limit ' ) as $ key ) {
77+ foreach (array ('type ' , 'file ' ) as $ key ) {
7778 $ container ->setParameter ('besimple.soap.cache. ' .$ key , $ config [$ key ]);
7879 }
7980 }
@@ -82,22 +83,33 @@ private function registerClientConfiguration(array $config, ContainerBuilder $co
8283 {
8384 $ loader ->load ('client.xml ' );
8485
85- foreach ($ config as $ client => $ options ) {
86- $ definition = new DefinitionDecorator ('besimple.soap.client.builder ' );
87- $ container ->setDefinition (sprintf ('besimple.soap.client.builder.%s ' , $ client ), $ definition );
88-
89- $ definition ->replaceArgument (0 , $ options ['wsdl ' ]);
90-
91- $ defOptions = $ container
92- ->getDefinition ('besimple.soap.client.builder ' )
93- ->getArgument (1 );
94-
95- foreach (array ('cache_type ' , 'user_agent ' ) as $ key ) {
96- if (isset ($ options [$ key ])) {
97- $ defOptions [$ key ] = $ options [$ key ];
98- }
99- }
100-
86+ foreach ($ config ['clients ' ] as $ client => $ options ) {
87+ $ soapClientOpts = new DefinitionDecorator ('besimple.soap.client_options ' );
88+ $ soapOpts = new DefinitionDecorator ('besimple.soap.options ' );
89+
90+ $ soapClientOptsService = sprintf ('besimple.soap.client_options.%s ' , $ client );
91+ $ soapOptsService = sprintf ('besimple.soap.options.%s ' , $ client );
92+
93+ // configure SoapClient
94+ $ definition = new DefinitionDecorator ('besimple.soap.client ' );
95+
96+ $ container ->setDefinition (
97+ sprintf ('besimple.soap.client.%s ' , $ client ),
98+ $ definition
99+ );
100+ $ container ->setDefinition (
101+ $ soapClientOptsService ,
102+ $ soapClientOpts
103+ );
104+ $ container ->setDefinition (
105+ $ soapOptsService ,
106+ $ soapOpts
107+ );
108+
109+ $ definition ->replaceArgument (0 , new Reference ($ soapClientOptsService ));
110+ $ definition ->replaceArgument (1 , new Reference ($ soapOptsService ));
111+
112+ // configure proxy
101113 $ proxy = $ options ['proxy ' ];
102114 if (false !== $ proxy ['host ' ]) {
103115 if (null !== $ proxy ['auth ' ]) {
@@ -108,49 +120,58 @@ private function registerClientConfiguration(array $config, ContainerBuilder $co
108120 }
109121 }
110122
111- $ definition ->addMethodCall ('withProxy ' , array (
112- $ proxy ['host ' ], $ proxy ['port ' ],
113- $ proxy ['login ' ], $ proxy ['password ' ],
114- $ proxy ['auth ' ]
115- ));
116- }
117-
118- if (isset ($ defOptions ['cache_type ' ])) {
119- $ defOptions ['cache_type ' ] = $ this ->getCacheType ($ defOptions ['cache_type ' ]);
123+ $ proxy = $ this ->createClientProxy ($ client , $ proxy , $ container );
124+ $ soapClientOpts ->setFactory ([
125+ '%besimple.soap.client_options_builder.class% ' ,
126+ 'createWithProxy '
127+ ]);
128+ $ soapClientOpts ->setArgument (0 , new Reference ($ proxy ));
120129 }
121130
122- $ definition ->replaceArgument (1 , $ defOptions );
131+ // configure SoapOptions for client
132+ $ classMap = $ this ->createClientClassMap ($ client , $ options ['classmap ' ], $ container );
123133
124- $ classmap = $ this ->createClientClassmap ($ client , $ options ['classmap ' ], $ container );
125- $ definition ->replaceArgument (2 , new Reference ($ classmap ));
134+ $ soapOpts ->replaceArgument (0 , $ config ['cache ' ]['file ' ]);
135+ $ soapOpts ->replaceArgument (1 , new Reference ($ classMap ));
136+ $ soapOpts ->replaceArgument (2 , $ this ->getCacheType ($ config ['cache ' ]['type ' ]));
126137
127- $ this ->createClient ($ client , $ container );
138+ if ($ config ['cache ' ]['version ' ] == SoapOptions::SOAP_VERSION_1_1 ) {
139+ $ soapOpts ->setFactory ([
140+ '%besimple.soap.options_builder.class% ' ,
141+ 'createWithClassMapV11 '
142+ ]);
143+ }
128144 }
129145 }
130146
131- private function createClientClassmap ($ client , array $ classmap , ContainerBuilder $ container )
147+ private function createClientClassMap ($ client , array $ classmap , ContainerBuilder $ container )
132148 {
133149 $ definition = new DefinitionDecorator ('besimple.soap.classmap ' );
134150 $ container ->setDefinition (sprintf ('besimple.soap.classmap.%s ' , $ client ), $ definition );
135151
136- if (! empty ($ classmap )) {
152+ if ( ! empty ($ classmap )) {
137153 $ definition ->setMethodCalls (array (
138- array ('set ' , array ($ classmap )),
154+ array ('__construct ' , array ($ classmap )),
139155 ));
140156 }
141157
142158 return sprintf ('besimple.soap.classmap.%s ' , $ client );
143159 }
144160
145- private function createClient ($ client , ContainerBuilder $ container )
161+ private function createClientProxy ($ client, array $ proxy , ContainerBuilder $ container )
146162 {
147- $ definition = new DefinitionDecorator ('besimple.soap.client ' );
148- $ container ->setDefinition (sprintf ('besimple.soap.client.%s ' , $ client ), $ definition );
163+ $ definition = new DefinitionDecorator ('besimple.soap.client.proxy ' );
164+ $ container ->setDefinition (sprintf ('besimple.soap.client.proxy.%s ' , $ client ), $ definition );
165+
166+ if ( ! empty ($ proxy )) {
167+ $ definition ->replaceArgument (0 , $ proxy ['host ' ]);
168+ $ definition ->replaceArgument (1 , $ proxy ['port ' ]);
169+ $ definition ->replaceArgument (2 , $ proxy ['login ' ]);
170+ $ definition ->replaceArgument (3 , $ proxy ['password ' ]);
171+ $ definition ->replaceArgument (4 , $ proxy ['auth ' ]);
172+ }
149173
150- $ definition ->setFactory (array (
151- new Reference (sprintf ('besimple.soap.client.builder.%s ' , $ client )),
152- 'build '
153- ));
174+ return sprintf ('besimple.soap.client.proxy.%s ' , $ client );
154175 }
155176
156177 private function createWebServiceContext (array $ config , ContainerBuilder $ container )
0 commit comments