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

@ -14,5 +14,5 @@ use BeSimple\SoapBundle\ServiceDefinition\ServiceDefinition;
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
{
private $loader;
private $options;
private $wsdl;
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);
$options = array_merge(array('endpoint' => '', 'stylesheet' => null), $options);
$this->definition = $definition;
$this->wsdl = new Wsdl($definition->getName(), $definition->getNamespace(), new WsdlTypeStrategy($this->loader, $definition));
$port = $this->wsdl->addPortType($this->getPortTypeName());
$binding = $this->wsdl->addBinding($this->getBindingName(), $this->qualify($this->getPortTypeName()));
$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) {
$requestParts = array();
@ -87,8 +88,8 @@ class WsdlDumper implements DumperInterface
$dom = $this->wsdl->toDomDocument();
$dom->formatOutput = true;
if (null !== $options['stylesheet']) {
$stylesheet = $dom->createProcessingInstruction('xml-stylesheet', sprintf('type="text/xsl" href="%s"', $options['stylesheet']));
if ($this->options['stylesheet']) {
$stylesheet = $dom->createProcessingInstruction('xml-stylesheet', sprintf('type="text/xsl" href="%s"', $this->options['stylesheet']));
$dom->insertBefore($stylesheet, $dom->documentElement);
}