Wsdl.php 1.89 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\Webapi\Model\Soap;

use DOMElement;
use Magento\Webapi\Model\Soap\Wsdl\ComplexTypeStrategy;

/**
 * Magento-specific WSDL builder.
 */
class Wsdl extends \Zend\Soap\Wsdl
{
    /**
     * Constructor.
     * Save URI for targetNamespace generation.
     *
     * @param string $name
     * @param string|\Zend\Uri\Uri $uri
     * @param ComplexTypeStrategy $strategy
     */
    public function __construct($name, $uri, ComplexTypeStrategy $strategy)
    {
        parent::__construct($name, $uri, $strategy);
    }

    /**
     * Add an operation to port type.
     *
     * @param DOMElement $portType
     * @param string $name Operation name
     * @param string|bool $input Input Message
     * @param string|bool $output Output Message
     * @param string|bool|array $fault Message name OR array('message' => ..., 'name' => ...)
     * @return object The new operation's XML_Tree_Node
     */
    public function addPortOperation($portType, $name, $input = false, $output = false, $fault = false)
    {
        $operation = parent::addPortOperation($portType, $name, $input, $output, false);
        if (is_array($fault)) {
            $isMessageValid = isset(
                $fault['message']
            ) && is_string(
                $fault['message']
            ) && strlen(
                trim($fault['message'])
            );
            $isNameValid = isset($fault['name']) && is_string($fault['name']) && strlen(trim($fault['name']));

            if ($isNameValid && $isMessageValid) {
                $node = $this->toDomDocument()->createElement('fault');
                $node->setAttribute('name', $fault['name']);
                $node->setAttribute('message', $fault['message']);
                $operation->appendChild($node);
            }
        }
        return $operation;
    }
}