BeSimple SoapBundle - 注释:处理复杂类型的循环引用

时间:2016-04-02 03:28:53

标签: php symfony soap doctrine

我正在使用BeSimple SoapBundle创建一个SOAP服务器,但我遇到了以下代码的问题:

namespace AppBundle\Entity;

use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap;

/**
 * @Soap\Alias("Item")
 */
class Item
{

    /**
     * @Soap\ComplexType("AppBundle\Entity\Item[]")
     */
    protected $items;

    /**
     * @Soap\ComplexType("string")
     */
    protected $name;

我需要得到的是一个复杂类型的树,但是当使用注释 @Soap \ ComplexType(“AppBundle \ Entity \ Item []”)时,我得到一个循环引用错误。

我知道如何应对这种情况?

1 个答案:

答案 0 :(得分:0)

我终于找到了解决此问题的方法。我认为它不应该是必要的,但却是我发现的最好和唯一的方式。

namespace AppBundle\Entity;

use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap;

/**
 * @Soap\Alias("ComplexItem")
 */
class ComplexItem extends Item
{        
    /**
     * @Soap\ComplexType("AppBundle\Entity\Item")
     */
    protected $item;

    public function setItem($item)
    {
        $this->item = $item;
    }
namespace AppBundle\Entity;

use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap;

class Item
{

    /**
     * @Soap\ComplexType("string")
     */
    protected $name;

控制器使用示例:

/**
 * @Soap\Method("getItem")
 * @Soap\Result(phpType = "AppBundle\Entity\ComplexItem")
 */
public function getItem()
{
    $item = new ComplexItem();
    $complexItem = new ComplexItem();
    $complexItem->setItem($item);

    return $complexItem;
}

希望它有所帮助。如果你知道更好的解决方法,请告诉我。