ServiceActionPerformerFactory.php 1.71 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
<?php
/**
 * @copyright  Vertex. All rights reserved.  https://www.vertexinc.com/
 * @author     Mediotype                     https://www.mediotype.com/
 */

namespace Vertex\Utility;

/**
 * Factory for ServiceActionPerformer
 */
class ServiceActionPerformerFactory
{
    /**
     * Create an instance of {@see ServiceActionPerformer}
     *
     * The following parameters are required for instantiation:
     * - `string $url`: WSDL URI
     * - `string $method`: SOAP method to be called
     * - `object $requestMapper`: (must be an object with a "map" method, should return a \stdClass)
     * - `object $responseMapper`: (must be an object with a "build" method)
     * - `AuthenticatorInterface $authenticator`: {@see \Vertex\Mapper\AuthenticatorInterface}
     *
     * @param mixed[] $parameters Indexed by parameter name
     * @return ServiceActionPerformer
     */
    public function create(array $parameters)
    {
        $requiredParameters = ['url', 'method', 'requestMapper', 'responseMapper', 'authenticator'];
        foreach ($requiredParameters as $parameterName) {
            if (!isset($parameters[$parameterName]) || empty($parameters[$parameterName])) {
                throw new \InvalidArgumentException('Missing required parameter: ' . $parameterName);
            }
        }

        return new ServiceActionPerformer(
            $parameters['url'],
            $parameters['method'],
            $parameters['requestMapper'],
            $parameters['responseMapper'],
            $parameters['authenticator'],
            isset($parameters['soapClientFactory']) ? $parameters['soapClientFactory'] : null,
            isset($parameters['faultConverter']) ? $parameters['faultConverter'] : null
        );
    }
}