扩展Symfony2 BeSimpleSoapBundle中的包

时间:2014-09-17 18:18:15

标签: php web-services symfony soap wsdl

我正在开发我的第一个“真正的”Symfony项目,它是一个SOAP api。我找到了BeSimple SoapBundle,我想为它添加一些似乎不受捆绑支持的复杂类型。除此之外,我想覆盖Dumper类中的以下函数:

protected function addComplexType(ComplexType $type)
{

}

它位于:besimple / soap-wsdl / BeSimple / SoapWsdl / Dumper / Dumper.php

我做的是以下内容。

我创建了src / Webstuff / SoapBundle / SoapWsdl / Dumper / Dumper.php

包含:

<?php
namespace Webstuff\SoapBundle\SoapWsdl\Dumper;

use BeSimple\SoapWsdl\Dumper as BaseDumper;
use BeSimple\SoapCommon\Definition\Definition;

class Dumper extends BaseDumper
{

    public function __construct(Definition $definition, array $options = array())
    {
        echo 'CHECK';
        exit;
    }

}

?>

我还将此添加到WebstuffSoapBundle.php

public function getParent(){
    return 'BeSimpleSoapBundle';
}

访问我的wsdl路径时,我希望看到CHECK。但它只是加载wsdl所以这个设置不起作用。我对Symfony很新,所以我可能会遗漏一些明显的东西。

希望有人可以帮助我朝着正确的方向前进!谢谢!

1 个答案:

答案 0 :(得分:0)

你需要: I.扩展WebServiceContext(位于: besimple / soap / src / BeSimple / SoapBundle / WebServiceContext.php ),以便能够在“{{1}中使用您的转储程序“方法而不是父转储器。

例如:

getWsdlFile

II。在<?php //Overriding WebServiceContext namespace Webstuff\SoapBundle; use Webstuff\SoapBundle\SoapWsdl\Dumper\Dumper; use Symfony\Component\Config\ConfigCache; class WebServiceContext extends \BeSimple\SoapBundle\WebServiceContext { private $options; public function __construct($loader, $converters, $options) { $this->options = $options; return parent::__construct($loader,$converters,$options); } public function getWsdlFile($endpoint = null) { $file = sprintf ('%s/%s.%s.wsdl', $this->options['cache_dir'], $this->options['name'], md5($endpoint)); $cache = new ConfigCache($file, $this->options['debug']); if(!$cache->isFresh()) { $definition = $this->getServiceDefinition(); if ($endpoint) { $definition->setOption('location', $endpoint); } $dumper = new Dumper($definition, array('stylesheet' => $this->options['wsdl_stylesheet'])); $cache->write($dumper->dump()); } return (string) $cache; } } ?php> 中设置“besimple.soap.context.class”参数,以引用您的config.yml扩展的类。

例如:

WebServiceContext