[
  {
    "path": ".gitignore",
    "content": ".idea"
  },
  {
    "path": "LICENSE",
    "content": "The MIT License (MIT)\n\nCopyright (c) 2014 Michael van de Rijt\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "Laravel SoapClient Wrapper\n===========================\n\nA SoapClient wrapper integration for Laravel.<br/>\nMakes it easy to use Soap in a Laravel application.<br/>\n\nPlease report any bugs or features here: <br/>\nhttps://github.com/artisaninweb/laravel-soap/issues/\n\nInstallation\n============\n\n## Laravel\n\n####Installation for Laravel 5.2 and above:\n\nRun `composer require artisaninweb/laravel-soap`\n\nAdd the service provider in `app/config/app.php`.\n\n```php\nArtisaninweb\\SoapWrapper\\ServiceProvider::class, \n```\n\nTo use the alias, add this to the aliases in `app/config/app.php`.\n\n```php\n'SoapWrapper' => Artisaninweb\\SoapWrapper\\Facade\\SoapWrapper::class,  \n```\n\n\n####Installation for Laravel 5.1 and below :\n\n\nAdd `artisaninweb/laravel-soap` as requirement to composer.json\n\n```javascript\n{\n    \"require\": {\n        \"artisaninweb/laravel-soap\": \"0.3.*\"\n    }\n}\n```\n\n> If you're using Laravel 5.5 or higher you can skip the two config setups below.\n\nAdd the service provider in `app/config/app.php`.\n\n```php\n'Artisaninweb\\SoapWrapper\\ServiceProvider'\n```\n\nTo use the facade add this to the facades in `app/config/app.php`.\n\n```php\n'SoapWrapper' => 'Artisaninweb\\SoapWrapper\\Facade'\n```\n\n## Lumen\n\nOpen `bootstrap/app.php` and register the required service provider:\n```php\n$app->register(Artisaninweb\\SoapWrapper\\ServiceProvider::class);\n```\n\nregister class alias:\n```php\nclass_alias('Artisaninweb\\SoapWrapper\\Facade', 'SoapWrapper');\n```\n\n*Facades must be enabled.*\n\n\nUsage\n============\n\nHow to add a service to the wrapper and use it.\n\n```php\n<?php\n\nnamespace App\\Http\\Controllers;\n\nuse Artisaninweb\\SoapWrapper\\SoapWrapper;\nuse App\\Soap\\Request\\GetConversionAmount;\nuse App\\Soap\\Response\\GetConversionAmountResponse;\n\nclass SoapController\n{\n  /**\n   * @var SoapWrapper\n   */\n  protected $soapWrapper;\n\n  /**\n   * SoapController constructor.\n   *\n   * @param SoapWrapper $soapWrapper\n   */\n  public function __construct(SoapWrapper $soapWrapper)\n  {\n    $this->soapWrapper = $soapWrapper;\n  }\n\n  /**\n   * Use the SoapWrapper\n   */\n  public function show() \n  {\n    $this->soapWrapper->add('Currency', function ($service) {\n      $service\n        ->wsdl('http://currencyconverter.kowabunga.net/converter.asmx?WSDL')\n        ->trace(true)\n        ->classmap([\n          GetConversionAmount::class,\n          GetConversionAmountResponse::class,\n        ]);\n    });\n\n    // Without classmap\n    $response = $this->soapWrapper->call('Currency.GetConversionAmount', [\n      'CurrencyFrom' => 'USD', \n      'CurrencyTo'   => 'EUR', \n      'RateDate'     => '2014-06-05', \n      'Amount'       => '1000',\n    ]);\n\n    var_dump($response);\n\n    // With classmap\n    $response = $this->soapWrapper->call('Currency.GetConversionAmount', [\n      new GetConversionAmount('USD', 'EUR', '2014-06-05', '1000')\n    ]);\n\n    var_dump($response);\n    exit;\n  }\n}\n```\n\nService functions\n============\n```php\n$this->soapWrapper->add('Currency', function ($service) {\n    $service\n        ->wsdl()                 // The WSDL url\n        ->trace(true)            // Optional: (parameter: true/false)\n        ->header()               // Optional: (parameters: $namespace,$name,$data,$mustunderstand,$actor)\n        ->customHeader()         // Optional: (parameters: $customerHeader) Use this to add a custom SoapHeader or extended class                \n        ->cookie()               // Optional: (parameters: $name,$value)\n        ->location()             // Optional: (parameter: $location)\n        ->certificate()          // Optional: (parameter: $certLocation)\n        ->cache(WSDL_CACHE_NONE) // Optional: Set the WSDL cache\n    \n        // Optional: Set some extra options\n        ->options([\n            'login' => 'username',\n            'password' => 'password'\n        ])\n\n        // Optional: Classmap\n        ->classmap([\n          GetConversionAmount::class,\n          GetConversionAmountResponse::class,\n        ]);\n});\n```\n\nClassmap\n============\n\nIf you are using classmap you can add folders like for example:\n- App\\Soap\n- App\\Soap\\Request\n- App\\Soap\\Response\n\nRequest: App\\Soap\\Request\\GetConversionAmount\n\n```php\n<?php\n\nnamespace App\\Soap\\Request;\n\nclass GetConversionAmount\n{\n  /**\n   * @var string\n   */\n  protected $CurrencyFrom;\n\n  /**\n   * @var string\n   */\n  protected $CurrencyTo;\n\n  /**\n   * @var string\n   */\n  protected $RateDate;\n\n  /**\n   * @var string\n   */\n  protected $Amount;\n\n  /**\n   * GetConversionAmount constructor.\n   *\n   * @param string $CurrencyFrom\n   * @param string $CurrencyTo\n   * @param string $RateDate\n   * @param string $Amount\n   */\n  public function __construct($CurrencyFrom, $CurrencyTo, $RateDate, $Amount)\n  {\n    $this->CurrencyFrom = $CurrencyFrom;\n    $this->CurrencyTo   = $CurrencyTo;\n    $this->RateDate     = $RateDate;\n    $this->Amount       = $Amount;\n  }\n\n  /**\n   * @return string\n   */\n  public function getCurrencyFrom()\n  {\n    return $this->CurrencyFrom;\n  }\n\n  /**\n   * @return string\n   */\n  public function getCurrencyTo()\n  {\n    return $this->CurrencyTo;\n  }\n\n  /**\n   * @return string\n   */\n  public function getRateDate()\n  {\n    return $this->RateDate;\n  }\n\n  /**\n   * @return string\n   */\n  public function getAmount()\n  {\n    return $this->Amount;\n  }\n}\n```\n\nResponse: App\\Soap\\Response\\GetConversionAmountResponse\n\n```php\n<?php\n\nnamespace App\\Soap\\Response;\n\nclass GetConversionAmountResponse\n{\n  /**\n   * @var string\n   */\n  protected $GetConversionAmountResult;\n\n  /**\n   * GetConversionAmountResponse constructor.\n   *\n   * @param string\n   */\n  public function __construct($GetConversionAmountResult)\n  {\n    $this->GetConversionAmountResult = $GetConversionAmountResult;\n  }\n\n  /**\n   * @return string\n   */\n  public function getGetConversionAmountResult()\n  {\n    return $this->GetConversionAmountResult;\n  }\n}\n```\n"
  },
  {
    "path": "composer.json",
    "content": "{\n    \"name\": \"artisaninweb/laravel-soap\",\n    \"description\": \"A SoapClient wrapper integration for Laravel\",\n    \"keywords\": [\"laravel\", \"soap\", \"client\", \"wrapper\"],\n    \"license\": \"MIT\",\n    \"authors\": [\n        {\n            \"name\": \"Michael van de Rijt\",\n            \"email\": \"me@mvdrijt.com\"\n        }\n    ],\n    \"require\": {\n        \"php\": \">=5.4.0\",\n        \"ext-soap\": \"*\"\n    },\n    \"autoload\": {\n        \"psr-0\": {\n            \"Artisaninweb\\\\SoapWrapper\": \"src/\"\n        }\n    },\n    \"extra\": {\n        \"laravel\": {\n            \"providers\": [\n                \"Artisaninweb\\\\SoapWrapper\\\\ServiceProvider\"\n            ],\n            \"aliases\": {\n                \"SoapWrapper\": \"Artisaninweb\\\\SoapWrapper\\\\Facade\"\n            }\n        }\n    }\n}\n"
  },
  {
    "path": "src/Artisaninweb/SoapWrapper/Client.php",
    "content": "<?php\n\nnamespace Artisaninweb\\SoapWrapper;\n\nuse SoapClient;\n\nclass Client extends SoapClient\n{\n  /**\n   * @var string\n   */\n  protected $wsdl;\n\n  /**\n   * Client constructor.\n   *\n   * @param string $wsdl\n   * @param array  $options\n   * @param array  $headers\n   */\n  public function __construct($wsdl, $options, array $headers = [])\n  {\n    parent::__construct($wsdl, $options);\n\n    if (!empty($headers)) {\n      $this->headers($headers);\n    }\n  }\n\n  /**\n   * Get all functions from the service\n   *\n   * @return mixed\n   */\n  public function getFunctions()\n  {\n    return $this->__getFunctions();\n  }\n\n  /**\n   * Get the last request\n   *\n   * @return mixed\n   */\n  public function getLastRequest()\n  {\n    return $this->__getLastRequest();\n  }\n\n  /**\n   * Get the last response\n   *\n   * @return mixed\n   */\n  public function getLastResponse()\n  {\n    return $this->__getLastResponse();\n  }\n\n  /**\n   * Get the last request headers\n   *\n   * @return mixed\n   */\n  public function getLastRequestHeaders()\n  {\n    return $this->__getLastRequestHeaders();\n  }\n\n  /**\n   * Get the last response headers\n   *\n   * @return mixed\n   */\n  public function getLastResponseHeaders()\n  {\n    return $this->__getLastResponseHeaders();\n  }\n\n  /**\n   * Get the types\n   *\n   * @return mixed\n   */\n  public function getTypes()\n  {\n    return $this->__getTypes();\n  }\n\n  /**\n   * Get all the set cookies\n   *\n   * @return mixed\n   */\n  public function getCookies()\n  {\n    return $this->__getCookies();\n  }\n\n  /**\n   * Set a new cookie\n   *\n   * @param string $name\n   * @param string $value\n   *\n   * @return $this\n   */\n  public function cookie($name, $value)\n  {\n    $this->__setCookie($name, $value);\n\n    return $this;\n  }\n\n  /**\n   * Set the location\n   *\n   * @param string $location\n   *\n   * @return $this\n   */\n  public function location($location = '')\n  {\n    $this->__setLocation($location);\n\n    return $this;\n  }\n\n  /**\n   * Set the Soap headers\n   *\n   * @param array $headers\n   *\n   * @return $this\n   */\n  protected function headers(array $headers = [])\n  {\n    $this->__setSoapHeaders($headers);\n\n    return $this;\n  }\n\n  /**\n   * Do soap request\n   *\n   * @param string $request\n   * @param string $location\n   * @param string $action\n   * @param string $version\n   * @param string $one_way\n   *\n   * @return mixed\n   */\n  public function doRequest($request, $location, $action, $version, $one_way)\n  {\n    return $this->__doRequest($request, $location, $action, $version, $one_way);\n  }\n\n  /**\n   * Do a soap call on the webservice client\n   *\n   * @param string $function\n   * @param array  $params\n   *\n   * @return mixed\n   */\n  public function call($function, $params)\n  {\n    return call_user_func_array([$this, $function], $params);\n  }\n\n  /**\n   * Allias to do a soap call on the webservice client\n   *\n   * @param string $function\n   * @param array  $params\n   * @param array  $options\n   * @param null   $inputHeader\n   * @param null   $outputHeaders\n   *\n   * @return mixed\n   */\n  public function SoapCall($function,\n    array $params,\n    array $options = null,\n    $inputHeader = null,\n    &$outputHeaders = null\n  ) {\n    return $this->__soapCall($function, $params, $options, $inputHeader, $outputHeaders);\n  }\n}\n"
  },
  {
    "path": "src/Artisaninweb/SoapWrapper/Exceptions/ServiceAlreadyExists.php",
    "content": "<?php\n\nnamespace Artisaninweb\\SoapWrapper\\Exceptions;\n\nuse Exception;\n\nclass ServiceAlreadyExists extends Exception\n{\n  //\n}\n"
  },
  {
    "path": "src/Artisaninweb/SoapWrapper/Exceptions/ServiceMethodNotExists.php",
    "content": "<?php\n\nnamespace Artisaninweb\\SoapWrapper\\Exceptions;\n\nuse Exception;\n\nclass ServiceMethodNotExists extends Exception\n{\n  //\n}\n"
  },
  {
    "path": "src/Artisaninweb/SoapWrapper/Exceptions/ServiceNotFound.php",
    "content": "<?php\n\nnamespace Artisaninweb\\SoapWrapper\\Exceptions;\n\nuse Exception;\n\nclass ServiceNotFound extends Exception\n{\n  //\n}\n"
  },
  {
    "path": "src/Artisaninweb/SoapWrapper/Facade.php",
    "content": "<?php\n\nnamespace Artisaninweb\\SoapWrapper;\n\nclass Facade extends \\Illuminate\\Support\\Facades\\Facade\n{\n  /**\n   * {@inheritDoc}\n   */\n  protected static function getFacadeAccessor()\n  {\n    return SoapWrapper::class;\n  }\n}\n"
  },
  {
    "path": "src/Artisaninweb/SoapWrapper/Service.php",
    "content": "<?php\n\nnamespace Artisaninweb\\SoapWrapper;\n\nuse SoapClient;\nuse SoapHeader;\n\nclass Service\n{\n  /**\n   * @var SoapClient\n   */\n  protected $client;\n\n  /**\n   * @var string\n   */\n  protected $wsdl;\n\n  /**\n   * @var boolean\n   */\n  protected $trace;\n\n  /**\n   * @var array\n   */\n  protected $headers;\n\n  /**\n   * @var string\n   */\n  protected $cache;\n\n  /**\n   * @var bool\n   */\n  protected $certificate;\n\n  /**\n   * @var array\n   */\n  protected $options;\n\n  /**\n   * @var array\n   */\n  protected $classmap;\n\n  /**\n   * Service constructor.\n   */\n  public function __construct()\n  {\n    $this->wsdl        = null;\n    $this->client      = null;\n    $this->certificate = false;\n    $this->options     = [];\n    $this->classmap    = [];\n    $this->headers     = [];\n  }\n\n  /**\n   * Set a custom client\n   *\n   * @param SoapClient $client\n   *\n   * @return $this\n   */\n  public function client(SoapClient $client)\n  {\n    $this->client = $client;\n\n    return $this;\n  }\n\n  /**\n   * Get the custom client\n   *\n   * @return SoapClient\n   */\n  public function getClient()\n  {\n    return $this->client;\n  }\n\n  /**\n   * Set the wsdl of the service\n   *\n   * @param string $wsdl\n   *\n   * @return $this\n   */\n  public function wsdl($wsdl)\n  {\n    $this->wsdl = $wsdl;\n\n    return $this;\n  }\n\n  /**\n   * Get the wsdl from the service\n   *\n   * @return string\n   */\n  public function getWsdl()\n  {\n    return $this->wsdl;\n  }\n\n  /**\n   * Set trace option - enables tracing of request\n   *\n   * @param boolean $trace\n   *\n   * @return $this\n   */\n  public function trace($trace)\n  {\n    $this->trace = $trace;\n\n    return $this;\n  }\n\n  /**\n   * Get the trace option\n   *\n   * @return boolean\n   */\n  public function getTrace()\n  {\n    return $this->trace;\n  }\n\n  /**\n   * Set the WSDL cache\n   *\n   * @param $cache\n   *\n   * @return $this\n   */\n  public function cache($cache)\n  {\n    $this->cache = $cache;\n\n    return $this;\n  }\n\n  /**\n   * Get the WSDL cache\n   *\n   * @return string\n   */\n  public function getCache()\n  {\n    return $this->cache;\n  }\n\n  /**\n   * @param array $classmap\n   *\n   * @return $this\n   */\n  public function classMap(array $classmap)\n  {\n    $this->classmap = $classmap;\n\n    return $this;\n  }\n\n  /**\n   * Get the classmap\n   *\n   * @return array\n   */\n  public function getClassmap()\n  {\n    $classmap = $this->classmap;\n    $classes  = [] ;\n\n    if (!empty($classmap)) {\n      foreach ($classmap as $class) {\n        // Can't use end because of strict mode :(\n        $name = current(array_slice(explode('\\\\', $class), -1, 1, true));\n\n        $classes[$name] = $class;\n      }\n    }\n\n    return $classes;\n  }\n\n  /**\n   * Set the extra options on the SoapClient\n   *\n   * @param array $options\n   *\n   * @return $this\n   */\n  public function options(array $options)\n  {\n    $this->options = $options;\n\n    return $this;\n  }\n\n  /**\n   * Get the extra options\n   *\n   * @return array\n   */\n  public function getOptions()\n  {\n    $options = [\n      'trace'      => $this->getTrace(),\n      'cache_wsdl' => $this->getCache(),\n      'classmap'   => $this->getClassmap(),\n    ];\n\n    if ($this->certificate) {\n      $options['local_cert'] = $this->certificate;\n    }\n\n    $this->options = array_merge($options, $this->options);\n\n    return $this->options;\n  }\n\n  /**\n   * Set the certificate location\n   *\n   * @param string $certificate\n   *\n   * @return $this\n   */\n  public function certificate($certificate)\n  {\n    if ($certificate) {\n      $this->certificate = $certificate;\n    }\n\n    return $this;\n  }\n\n    /**\n     * Get the headers\n     *\n     * @return array\n     */\n    public function getHeaders()\n    {\n        return $this->headers;\n    }\n\n  /**\n   * Create a new SoapHeader\n   *\n   * @param string $namespace\n   * @param string $name\n   * @param null   $data\n   * @param bool   $mustUnderstand\n   * @param null   $actor\n   *\n   * @return $this\n   */\n  public function header($namespace, $name, $data = null, $mustUnderstand = false, $actor = null)\n  {\n    if ($actor) {\n      $this->headers[] = new SoapHeader($namespace, $name, $data, $mustUnderstand, $actor);\n    } else {\n      $this->headers[] = new SoapHeader($namespace, $name, $data, $mustUnderstand);\n    }\n\n    return $this;\n  }\n\n  /**\n   * Set the Soap headers\n   *\n   * @param SoapHeader $header\n   *\n   * @return $this\n   */\n  public function customHeader($header)\n  {\n    $this->headers[] = $header;\n\n    return $this;\n  }\n}\n"
  },
  {
    "path": "src/Artisaninweb/SoapWrapper/ServiceProvider.php",
    "content": "<?php\n\nnamespace Artisaninweb\\SoapWrapper;\n\nuse \\Illuminate\\Support\\ServiceProvider as LaravelServiceProvider;\n\nclass ServiceProvider extends LaravelServiceProvider\n{\n  /**\n   * Bootstrap the application events.\n   *\n   * @return void\n   */\n  public function boot()\n  {\n    // Nothing here\n  }\n\n  /**\n   * Register the service provider.\n   *\n   * @return void\n   */\n  public function register()\n  {\n    $soapWrapper = new SoapWrapper();\n\n    if (is_array($this->app['config']['soapwrapper'])) {\n      $soapWrapper->addByArray($this->app['config']['soapwrapper']);\n    }\n\n    $this->app->bindIf(SoapWrapper::class, function () use ($soapWrapper) {\n      return $soapWrapper;\n    });\n  }\n}\n"
  },
  {
    "path": "src/Artisaninweb/SoapWrapper/SoapWrapper.php",
    "content": "<?php\n\nnamespace Artisaninweb\\SoapWrapper;\n\nuse Closure;\nuse SoapClient;\nuse Artisaninweb\\SoapWrapper\\Exceptions\\ServiceNotFound;\nuse Artisaninweb\\SoapWrapper\\Exceptions\\ServiceAlreadyExists;\nuse Artisaninweb\\SoapWrapper\\Exceptions\\ServiceMethodNotExists;\n\nclass SoapWrapper\n{\n  /**\n   * @var array\n   */\n  protected $services;\n\n  /**\n   * SoapWrapper constructor\n   */\n  public function __construct()\n  {\n    $this->services = [];\n  }\n\n  /**\n   * Add a new service to the wrapper\n   *\n   * @param string  $name\n   * @param Closure $closure\n   *\n   * @return $this\n   * @throws ServiceAlreadyExists\n   */\n  public function add($name, Closure $closure)\n  {\n    if (!$this->has($name)) {\n      $service = new Service();\n\n      $closure($service);\n\n      $this->services[$name] = $service;\n\n      return $this;\n    }\n\n    throw new ServiceAlreadyExists(\"Service '\" . $name . \"' already exists.\");\n  }\n\n  /**\n   * Add services by array\n   *\n   * @param array $services\n   *\n   * @return $this\n   *\n   * @throws ServiceAlreadyExists\n   * @throws ServiceMethodNotExists\n   */\n  public function addByArray(array $services = [])\n  {\n    if (!empty($services)) {\n      foreach ($services as $name => $methods) {\n        if (!$this->has($name)) {\n          $service = new Service();\n\n          foreach ($methods as $method => $value) {\n            if (method_exists($service, $method)) {\n              $service->{$method}($value);\n            } else {\n                throw new ServiceMethodNotExists(sprintf(\n                  \"Method '%s' does not exists on the %s service.\",\n                  $method,\n                  $name\n                ));\n              }\n          }\n\n          $this->services[$name] = $service;\n\n          continue;\n        }\n\n        throw new ServiceAlreadyExists(sprintf(\n          \"Service '%s' already exists.\",\n          $name\n        ));\n      }\n    }\n\n    return $this;\n  }\n\n  /**\n   * Get the client\n   *\n   * @param string  $name\n   * @param Closure $closure\n   *\n   * @return mixed\n   * @throws ServiceNotFound\n   */\n    public function client($name, Closure $closure = null)\n    {\n        if ($this->has($name)) {\n            /** @var Service $service */\n            $service = $this->services[$name];\n\n            if (is_null($service->getClient())) {\n                $client = new Client($service->getWsdl(), $service->getOptions(), $service->getHeaders());\n              \n                $service->client($client);\n            } else {\n                $client = $service->getClient();\n            }\n\n            return $closure($client);\n        }\n\n        throw new ServiceNotFound(\"Service '\" . $name . \"' not found.\");\n    }\n\n  /**\n   * A easy access call method\n   *\n   * @param string $call\n   * @param array  $data\n   *\n   * @return mixed\n   */\n  public function call($call, $data = [], $options = [])\n  {\n    list($name, $function) = explode('.', $call, 2);\n\n    return $this->client($name, function ($client) use ($function, $data, $options) {\n      /** @var Client $client */\n      return $client->SoapCall($function, $data, $options);\n    });\n  }\n\n  /**\n   * Check if wrapper has service\n   *\n   * @param string $name\n   *\n   * @return bool\n   */\n  public function has($name)\n  {\n    return (array_key_exists($name, $this->services));\n  }\n}\n"
  }
]