簡體   English   中英

在Symfony2 BeSimpleSoapBundle中擴展包

[英]Extending bundles in Symfony2 BeSimpleSoapBundle

我正在開發我的第一個“真實” 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的新手,所以我可能會錯過一些明顯的東西。

希望有人能給我一個正確的方向! 謝謝!

您需要:I.擴展WebServiceContext (位於: besimple / soap / src / BeSimple / SoapBundle / WebServiceContext.php ),以便能夠使用“ getWsdlFile ”方法中的轉儲程序而不是父轉儲程序。

例如:

<?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>

二。 config.yml設置“ besimple.soap.context.class ”參數以引用擴展WebServiceContext的類。

例如:

# app/config/config.yml
parameters:
besimple.soap.context.class: "Webstuff\SoapBundle\WebServiceContext"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM