Moved stylesheet option in WsdlDumper service and add the possibility to configure

This commit is contained in:
Francis Besset 2011-08-14 21:59:03 +02:00
parent 33165ce8d2
commit 0e177bd067
6 changed files with 39 additions and 12 deletions

View File

@ -43,6 +43,8 @@ class BeSimpleSoapExtension extends Extension
$config = $processor->process($configuration->getConfigTree(), $configs); $config = $processor->process($configuration->getConfigTree(), $configs);
$container->setParameter('besimple.soap.definition.dumper.options.stylesheet', $config['wsdl_dumper']['stylesheet']);
foreach($config['services'] as $name => $serviceConfig) { foreach($config['services'] as $name => $serviceConfig) {
$serviceConfig['name'] = $name; $serviceConfig['name'] = $name;
$this->createWebServiceContext($serviceConfig, $container); $this->createWebServiceContext($serviceConfig, $container);

View File

@ -10,6 +10,7 @@
namespace BeSimple\SoapBundle\DependencyInjection; namespace BeSimple\SoapBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\Builder\TreeBuilder;
/** /**
@ -27,8 +28,16 @@ class Configuration
public function getConfigTree() public function getConfigTree()
{ {
$treeBuilder = new TreeBuilder(); $treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('web_service'); $rootNode = $treeBuilder->root('be_simple_soap');
$this->addServicesSection($rootNode);
$this->addWsdlDumperSection($rootNode);
return $treeBuilder->buildTree();
}
private function addServicesSection(ArrayNodeDefinition $rootNode)
{
$rootNode $rootNode
->children() ->children()
->arrayNode('services') ->arrayNode('services')
@ -55,7 +64,19 @@ class Configuration
->end() ->end()
->end() ->end()
; ;
}
return $treeBuilder->buildTree(); private function addWsdlDumperSection(ArrayNodeDefinition $rootNode)
{
$rootNode
->children()
->arrayNode('wsdl_dumper')
->addDefaultsIfNotSet()
->children()
->scalarNode('stylesheet')->defaultNull()
->end()
->end()
->end()
;
} }
} }

View File

@ -44,6 +44,9 @@
<service id="besimple.soap.definition.dumper.wsdl.rpcliteral" class="%besimple.soap.definition.dumper.wsdl.rpcliteral.class%"> <service id="besimple.soap.definition.dumper.wsdl.rpcliteral" class="%besimple.soap.definition.dumper.wsdl.rpcliteral.class%">
<argument type="service" id="besimple.soap.definition.loader.annot_complextype" /> <argument type="service" id="besimple.soap.definition.loader.annot_complextype" />
<argument type="collection">
<argument key="stylesheet">%besimple.soap.definition.dumper.options.stylesheet%</argument>
</argument>
</service> </service>
<service id="besimple.soap.converter.repository" class="%besimple.soap.converter.repository.class%" /> <service id="besimple.soap.converter.repository" class="%besimple.soap.converter.repository.class%" />

View File

@ -14,5 +14,5 @@ use BeSimple\SoapBundle\ServiceDefinition\ServiceDefinition;
interface DumperInterface interface DumperInterface
{ {
function dumpServiceDefinition(ServiceDefinition $definition, array $options = array()); function dumpServiceDefinition(ServiceDefinition $definition, $endpoint);
} }

View File

@ -25,27 +25,28 @@ use Zend\Soap\Wsdl;
class WsdlDumper implements DumperInterface class WsdlDumper implements DumperInterface
{ {
private $loader; private $loader;
private $options;
private $wsdl; private $wsdl;
private $definition; private $definition;
public function __construct(AnnotationComplexTypeLoader $loader) public function __construct(AnnotationComplexTypeLoader $loader, array $options)
{ {
$this->loader = $loader; $this->loader = $loader;
$this->options = $options;
} }
public function dumpServiceDefinition(ServiceDefinition $definition, array $options = array()) public function dumpServiceDefinition(ServiceDefinition $definition, $endpoint)
{ {
Assert::thatArgumentNotNull('definition', $definition); Assert::thatArgumentNotNull('definition', $definition);
$options = array_merge(array('endpoint' => '', 'stylesheet' => null), $options);
$this->definition = $definition; $this->definition = $definition;
$this->wsdl = new Wsdl($definition->getName(), $definition->getNamespace(), new WsdlTypeStrategy($this->loader, $definition)); $this->wsdl = new Wsdl($definition->getName(), $definition->getNamespace(), new WsdlTypeStrategy($this->loader, $definition));
$port = $this->wsdl->addPortType($this->getPortTypeName()); $port = $this->wsdl->addPortType($this->getPortTypeName());
$binding = $this->wsdl->addBinding($this->getBindingName(), $this->qualify($this->getPortTypeName())); $binding = $this->wsdl->addBinding($this->getBindingName(), $this->qualify($this->getPortTypeName()));
$this->wsdl->addSoapBinding($binding, 'rpc'); $this->wsdl->addSoapBinding($binding, 'rpc');
$this->wsdl->addService($this->getServiceName(), $this->getPortName(), $this->qualify($this->getBindingName()), $options['endpoint']); $this->wsdl->addService($this->getServiceName(), $this->getPortName(), $this->qualify($this->getBindingName()), $endpoint);
foreach ($definition->getMethods() as $method) { foreach ($definition->getMethods() as $method) {
$requestParts = array(); $requestParts = array();
@ -87,8 +88,8 @@ class WsdlDumper implements DumperInterface
$dom = $this->wsdl->toDomDocument(); $dom = $this->wsdl->toDomDocument();
$dom->formatOutput = true; $dom->formatOutput = true;
if (null !== $options['stylesheet']) { if ($this->options['stylesheet']) {
$stylesheet = $dom->createProcessingInstruction('xml-stylesheet', sprintf('type="text/xsl" href="%s"', $options['stylesheet'])); $stylesheet = $dom->createProcessingInstruction('xml-stylesheet', sprintf('type="text/xsl" href="%s"', $this->options['stylesheet']));
$dom->insertBefore($stylesheet, $dom->documentElement); $dom->insertBefore($stylesheet, $dom->documentElement);
} }

View File

@ -76,7 +76,7 @@ class WebServiceContext
$cache = new ConfigCache($file, $this->options['debug']); $cache = new ConfigCache($file, $this->options['debug']);
if(!$cache->isFresh()) { if(!$cache->isFresh()) {
$cache->write($this->wsdlFileDumper->dumpServiceDefinition($this->getServiceDefinition(), array('endpoint' => $endpoint))); $cache->write($this->wsdlFileDumper->dumpServiceDefinition($this->getServiceDefinition(), $endpoint));
} }
return (string) $cache; return (string) $cache;