diff --git a/.gitignore b/.gitignore index 723ef36..3ce5adb 100755 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.idea \ No newline at end of file +.idea +vendor diff --git a/composer.json b/composer.json index 887221b..bb9ce3d 100755 --- a/composer.json +++ b/composer.json @@ -10,8 +10,9 @@ } ], "require": { - "php": ">=5.4.0", - "ext-soap": "*" + "php": ">=5.5", + "ext-soap": "*", + "illuminate/support": ">=5.5" }, "autoload": { "psr-0": { diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..1b4a221 --- /dev/null +++ b/composer.lock @@ -0,0 +1,563 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "cca3ba9c69e4e10cdd73306967e350c2", + "packages": [ + { + "name": "doctrine/inflector", + "version": "v1.2.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/inflector.git", + "reference": "e11d84c6e018beedd929cff5220969a3c6d1d462" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/inflector/zipball/e11d84c6e018beedd929cff5220969a3c6d1d462", + "reference": "e11d84c6e018beedd929cff5220969a3c6d1d462", + "shasum": "" + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\Inflector\\": "lib/Doctrine/Common/Inflector" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Common String Manipulations with regard to casing and singular/plural rules.", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "inflection", + "pluralize", + "singularize", + "string" + ], + "time": "2017-07-22T12:18:28+00:00" + }, + { + "name": "illuminate/contracts", + "version": "v5.5.44", + "source": { + "type": "git", + "url": "https://github.com/illuminate/contracts.git", + "reference": "b2a62b4a85485fca9cf5fa61a933ad64006ff528" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/illuminate/contracts/zipball/b2a62b4a85485fca9cf5fa61a933ad64006ff528", + "reference": "b2a62b4a85485fca9cf5fa61a933ad64006ff528", + "shasum": "" + }, + "require": { + "php": ">=7.0", + "psr/container": "~1.0", + "psr/simple-cache": "~1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.5-dev" + } + }, + "autoload": { + "psr-4": { + "Illuminate\\Contracts\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "The Illuminate Contracts package.", + "homepage": "https://laravel.com", + "time": "2018-03-20T15:34:35+00:00" + }, + { + "name": "illuminate/support", + "version": "v5.5.44", + "source": { + "type": "git", + "url": "https://github.com/illuminate/support.git", + "reference": "5c405512d75dcaf5d37791badce02d86ed8e4bc4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/illuminate/support/zipball/5c405512d75dcaf5d37791badce02d86ed8e4bc4", + "reference": "5c405512d75dcaf5d37791badce02d86ed8e4bc4", + "shasum": "" + }, + "require": { + "doctrine/inflector": "~1.1", + "ext-mbstring": "*", + "illuminate/contracts": "5.5.*", + "nesbot/carbon": "^1.24.1", + "php": ">=7.0" + }, + "replace": { + "tightenco/collect": "<5.5.33" + }, + "suggest": { + "illuminate/filesystem": "Required to use the composer class (5.5.*).", + "symfony/process": "Required to use the composer class (~3.3).", + "symfony/var-dumper": "Required to use the dd function (~3.3)." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.5-dev" + } + }, + "autoload": { + "psr-4": { + "Illuminate\\Support\\": "" + }, + "files": [ + "helpers.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "The Illuminate Support package.", + "homepage": "https://laravel.com", + "time": "2018-08-10T19:40:01+00:00" + }, + { + "name": "kylekatarnls/update-helper", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/kylekatarnls/update-helper.git", + "reference": "429be50660ed8a196e0798e5939760f168ec8ce9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/kylekatarnls/update-helper/zipball/429be50660ed8a196e0798e5939760f168ec8ce9", + "reference": "429be50660ed8a196e0798e5939760f168ec8ce9", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.1.0 || ^2.0.0", + "php": ">=5.3.0" + }, + "require-dev": { + "codeclimate/php-test-reporter": "dev-master", + "composer/composer": "2.0.x-dev || ^2.0.0-dev", + "phpunit/phpunit": ">=4.8.35 <6.0" + }, + "type": "composer-plugin", + "extra": { + "class": "UpdateHelper\\ComposerPlugin" + }, + "autoload": { + "psr-0": { + "UpdateHelper\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kyle", + "email": "kylekatarnls@gmail.com" + } + ], + "description": "Update helper", + "funding": [ + { + "url": "https://github.com/kylekatarnls", + "type": "github" + }, + { + "url": "https://opencollective.com/Carbon", + "type": "open_collective" + }, + { + "url": "https://tidelift.com/funding/github/packagist/nesbot/carbon", + "type": "tidelift" + } + ], + "time": "2020-04-07T20:44:10+00:00" + }, + { + "name": "nesbot/carbon", + "version": "1.39.1", + "source": { + "type": "git", + "url": "https://github.com/briannesbitt/Carbon.git", + "reference": "4be0c005164249208ce1b5ca633cd57bdd42ff33" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/4be0c005164249208ce1b5ca633cd57bdd42ff33", + "reference": "4be0c005164249208ce1b5ca633cd57bdd42ff33", + "shasum": "" + }, + "require": { + "kylekatarnls/update-helper": "^1.1", + "php": ">=5.3.9", + "symfony/translation": "~2.6 || ~3.0 || ~4.0" + }, + "require-dev": { + "composer/composer": "^1.2", + "friendsofphp/php-cs-fixer": "~2", + "phpunit/phpunit": "^4.8.35 || ^5.7" + }, + "bin": [ + "bin/upgrade-carbon" + ], + "type": "library", + "extra": { + "update-helper": "Carbon\\Upgrade", + "laravel": { + "providers": [ + "Carbon\\Laravel\\ServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Brian Nesbitt", + "email": "brian@nesbot.com", + "homepage": "http://nesbot.com" + } + ], + "description": "A simple API extension for DateTime.", + "homepage": "http://carbon.nesbot.com", + "keywords": [ + "date", + "datetime", + "time" + ], + "time": "2019-10-14T05:51:36+00:00" + }, + { + "name": "psr/container", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/container.git", + "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/container/zipball/b7ce3b176482dbbc1245ebf52b181af44c2cf55f", + "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Container\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common Container Interface (PHP FIG PSR-11)", + "homepage": "https://github.com/php-fig/container", + "keywords": [ + "PSR-11", + "container", + "container-interface", + "container-interop", + "psr" + ], + "time": "2017-02-14T16:28:37+00:00" + }, + { + "name": "psr/simple-cache", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/simple-cache.git", + "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/simple-cache/zipball/408d5eafb83c57f6365a3ca330ff23aa4a5fa39b", + "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\SimpleCache\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interfaces for simple caching", + "keywords": [ + "cache", + "caching", + "psr", + "psr-16", + "simple-cache" + ], + "time": "2017-10-23T01:57:42+00:00" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.19.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "b5f7b932ee6fa802fc792eabd77c4c88084517ce" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/b5f7b932ee6fa802fc792eabd77c4c88084517ce", + "reference": "b5f7b932ee6fa802fc792eabd77c4c88084517ce", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.19-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-10-23T09:01:57+00:00" + }, + { + "name": "symfony/translation", + "version": "v3.4.47", + "source": { + "type": "git", + "url": "https://github.com/symfony/translation.git", + "reference": "be83ee6c065cb32becdb306ba61160d598b1ce88" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/translation/zipball/be83ee6c065cb32becdb306ba61160d598b1ce88", + "reference": "be83ee6c065cb32becdb306ba61160d598b1ce88", + "shasum": "" + }, + "require": { + "php": "^5.5.9|>=7.0.8", + "symfony/polyfill-mbstring": "~1.0" + }, + "conflict": { + "symfony/config": "<2.8", + "symfony/dependency-injection": "<3.4", + "symfony/yaml": "<3.4" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "~2.8|~3.0|~4.0", + "symfony/dependency-injection": "~3.4|~4.0", + "symfony/finder": "~2.8|~3.0|~4.0", + "symfony/http-kernel": "~3.4|~4.0", + "symfony/intl": "^2.8.18|^3.2.5|~4.0", + "symfony/var-dumper": "~3.4|~4.0", + "symfony/yaml": "~3.4|~4.0" + }, + "suggest": { + "psr/log-implementation": "To use logging capability in translator", + "symfony/config": "", + "symfony/yaml": "" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Translation\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Translation Component", + "homepage": "https://symfony.com", + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-10-24T10:57:07+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">=5.4.0", + "ext-soap": "*" + }, + "platform-dev": [], + "plugin-api-version": "1.1.0" +} diff --git a/src/Artisaninweb/SoapWrapper/Client.php b/src/Artisaninweb/SoapWrapper/Client.php index cbff403..48cf583 100644 --- a/src/Artisaninweb/SoapWrapper/Client.php +++ b/src/Artisaninweb/SoapWrapper/Client.php @@ -2,190 +2,192 @@ namespace Artisaninweb\SoapWrapper; +use Artisaninweb\SoapWrapper\Contracts\SoapClientDecorator as SoapClientDecoratorContract; use SoapClient; -class Client extends SoapClient +class Client extends SoapClient implements SoapClientDecoratorContract { - /** - * @var string - */ - protected $wsdl; - - /** - * Client constructor. - * - * @param string $wsdl - * @param array $options - * @param array $headers - */ - public function __construct($wsdl, $options, array $headers = []) - { - parent::__construct($wsdl, $options); - - if (!empty($headers)) { - $this->headers($headers); + /** + * @var string + */ + protected $wsdl; + + /** + * Client constructor. + * + * @param string $wsdl + * @param array $options + * @param array $headers + */ + public function __construct($wsdl, $options, array $headers = []) + { + parent::__construct($wsdl, $options); + + if (!empty($headers)) { + $this->headers($headers); + } + } + + /** + * Get all functions from the service + * + * @return mixed + */ + public function getFunctions() + { + return $this->__getFunctions(); + } + + /** + * Get the last request + * + * @return mixed + */ + public function getLastRequest() + { + return $this->__getLastRequest(); + } + + /** + * Get the last response + * + * @return mixed + */ + public function getLastResponse() + { + return $this->__getLastResponse(); + } + + /** + * Get the last request headers + * + * @return mixed + */ + public function getLastRequestHeaders() + { + return $this->__getLastRequestHeaders(); + } + + /** + * Get the last response headers + * + * @return mixed + */ + public function getLastResponseHeaders() + { + return $this->__getLastResponseHeaders(); + } + + /** + * Get the types + * + * @return mixed + */ + public function getTypes() + { + return $this->__getTypes(); + } + + /** + * Get all the set cookies + * + * @return mixed + */ + public function getCookies() + { + return $this->__getCookies(); + } + + /** + * Set a new cookie + * + * @param string $name + * @param string $value + * + * @return $this + */ + public function cookie($name, $value) + { + $this->__setCookie($name, $value); + + return $this; + } + + /** + * Set the location + * + * @param string $location + * + * @return $this + */ + public function location($location = '') + { + $this->__setLocation($location); + + return $this; + } + + /** + * Set the Soap headers + * + * @param array $headers + * + * @return $this + */ + protected function headers(array $headers = []) + { + $this->__setSoapHeaders($headers); + + return $this; + } + + /** + * Do soap request + * + * @param string $request + * @param string $location + * @param string $action + * @param string $version + * @param string $one_way + * + * @return mixed + */ + public function doRequest($request, $location, $action, $version, $one_way) + { + return $this->__doRequest($request, $location, $action, $version, $one_way); + } + + /** + * Do a soap call on the webservice client + * + * @param string $function + * @param array $params + * + * @return mixed + */ + public function call($function, $params) + { + return call_user_func_array([$this, $function], $params); + } + + /** + * Allias to do a soap call on the webservice client + * + * @param string $function + * @param array $params + * @param array $options + * @param null $inputHeader + * @param null $outputHeaders + * + * @return mixed + */ + public function SoapCall( + $function, + array $params, + array $options = null, + $inputHeader = null, + &$outputHeaders = null + ) { + return $this->__soapCall($function, $params, $options, $inputHeader, $outputHeaders); } - } - - /** - * Get all functions from the service - * - * @return mixed - */ - public function getFunctions() - { - return $this->__getFunctions(); - } - - /** - * Get the last request - * - * @return mixed - */ - public function getLastRequest() - { - return $this->__getLastRequest(); - } - - /** - * Get the last response - * - * @return mixed - */ - public function getLastResponse() - { - return $this->__getLastResponse(); - } - - /** - * Get the last request headers - * - * @return mixed - */ - public function getLastRequestHeaders() - { - return $this->__getLastRequestHeaders(); - } - - /** - * Get the last response headers - * - * @return mixed - */ - public function getLastResponseHeaders() - { - return $this->__getLastResponseHeaders(); - } - - /** - * Get the types - * - * @return mixed - */ - public function getTypes() - { - return $this->__getTypes(); - } - - /** - * Get all the set cookies - * - * @return mixed - */ - public function getCookies() - { - return $this->__getCookies(); - } - - /** - * Set a new cookie - * - * @param string $name - * @param string $value - * - * @return $this - */ - public function cookie($name, $value) - { - $this->__setCookie($name, $value); - - return $this; - } - - /** - * Set the location - * - * @param string $location - * - * @return $this - */ - public function location($location = '') - { - $this->__setLocation($location); - - return $this; - } - - /** - * Set the Soap headers - * - * @param array $headers - * - * @return $this - */ - protected function headers(array $headers = []) - { - $this->__setSoapHeaders($headers); - - return $this; - } - - /** - * Do soap request - * - * @param string $request - * @param string $location - * @param string $action - * @param string $version - * @param string $one_way - * - * @return mixed - */ - public function doRequest($request, $location, $action, $version, $one_way) - { - return $this->__doRequest($request, $location, $action, $version, $one_way); - } - - /** - * Do a soap call on the webservice client - * - * @param string $function - * @param array $params - * - * @return mixed - */ - public function call($function, $params) - { - return call_user_func_array([$this, $function], $params); - } - - /** - * Allias to do a soap call on the webservice client - * - * @param string $function - * @param array $params - * @param array $options - * @param null $inputHeader - * @param null $outputHeaders - * - * @return mixed - */ - public function SoapCall($function, - array $params, - array $options = null, - $inputHeader = null, - &$outputHeaders = null - ) { - return $this->__soapCall($function, $params, $options, $inputHeader, $outputHeaders); - } } diff --git a/src/Artisaninweb/SoapWrapper/Contracts/Service.php b/src/Artisaninweb/SoapWrapper/Contracts/Service.php new file mode 100644 index 0000000..ff66692 --- /dev/null +++ b/src/Artisaninweb/SoapWrapper/Contracts/Service.php @@ -0,0 +1,141 @@ +wsdl = null; - $this->client = null; - $this->certificate = false; - $this->options = []; - $this->classmap = []; - $this->headers = []; - } - - /** - * Set a custom client - * - * @param SoapClient $client - * - * @return $this - */ - public function client(SoapClient $client) - { - $this->client = $client; - - return $this; - } - - /** - * Get the custom client - * - * @return SoapClient - */ - public function getClient() - { - return $this->client; - } - - /** - * Set the wsdl of the service - * - * @param string $wsdl - * - * @return $this - */ - public function wsdl($wsdl) - { - $this->wsdl = $wsdl; - - return $this; - } - - /** - * Get the wsdl from the service - * - * @return string - */ - public function getWsdl() - { - return $this->wsdl; - } - - /** - * Set trace option - enables tracing of request - * - * @param boolean $trace - * - * @return $this - */ - public function trace($trace) - { - $this->trace = $trace; - - return $this; - } - - /** - * Get the trace option - * - * @return boolean - */ - public function getTrace() - { - return $this->trace; - } - - /** - * Set the WSDL cache - * - * @param $cache - * - * @return $this - */ - public function cache($cache) - { - $this->cache = $cache; - - return $this; - } - - /** - * Get the WSDL cache - * - * @return string - */ - public function getCache() - { - return $this->cache; - } - - /** - * @param array $classmap - * - * @return $this - */ - public function classMap(array $classmap) - { - $this->classmap = $classmap; - - return $this; - } - - /** - * Get the classmap - * - * @return array - */ - public function getClassmap() - { - $classmap = $this->classmap; - $classes = [] ; - - if (!empty($classmap)) { - foreach ($classmap as $class) { - // Can't use end because of strict mode :( - $name = current(array_slice(explode('\\', $class), -1, 1, true)); - - $classes[$name] = $class; - } + /** + * @var SoapClientDecoratorContract + */ + protected $client; + + /** + * @var string + */ + protected $wsdl; + + /** + * @var boolean + */ + protected $trace; + + /** + * @var array + */ + protected $headers; + + /** + * @var string + */ + protected $cache; + + /** + * @var bool + */ + protected $certificate; + + /** + * @var array + */ + protected $options; + + /** + * @var array + */ + protected $classmap; + + /** + * Service constructor. + */ + public function __construct() + { + $this->wsdl = null; + $this->client = null; + $this->certificate = false; + $this->options = []; + $this->classmap = []; + $this->headers = []; + } + + /** + * Set a custom client + * + * @param SoapClientDecoratorContract $client + * + * @return $this + */ + public function client(SoapClientDecoratorContract $client) + { + $this->client = $client; + + return $this; + } + + /** + * Get the custom client + * + * @return SoapClientDecoratorContract + */ + public function getClient() + { + return $this->client; + } + + /** + * Set the wsdl of the service + * + * @param string $wsdl + * + * @return $this + */ + public function wsdl($wsdl) + { + $this->wsdl = $wsdl; + + return $this; + } + + /** + * Get the wsdl from the service + * + * @return string + */ + public function getWsdl() + { + return $this->wsdl; + } + + /** + * Set trace option - enables tracing of request + * + * @param boolean $trace + * + * @return $this + */ + public function trace($trace) + { + $this->trace = $trace; + + return $this; + } + + /** + * Get the trace option + * + * @return boolean + */ + public function getTrace() + { + return $this->trace; } - return $classes; - } - - /** - * Set the extra options on the SoapClient - * - * @param array $options - * - * @return $this - */ - public function options(array $options) - { - $this->options = $options; - - return $this; - } - - /** - * Get the extra options - * - * @return array - */ - public function getOptions() - { - $options = [ - 'trace' => $this->getTrace(), - 'cache_wsdl' => $this->getCache(), - 'classmap' => $this->getClassmap(), - ]; - - if ($this->certificate) { - $options['local_cert'] = $this->certificate; + /** + * Set the WSDL cache + * + * @param $cache + * + * @return $this + */ + public function cache($cache) + { + $this->cache = $cache; + + return $this; } - $this->options = array_merge($options, $this->options); - - return $this->options; - } - - /** - * Set the certificate location - * - * @param string $certificate - * - * @return $this - */ - public function certificate($certificate) - { - if ($certificate) { - $this->certificate = $certificate; + /** + * Get the WSDL cache + * + * @return string + */ + public function getCache() + { + return $this->cache; + } + + /** + * @param array $classmap + * + * @return $this + */ + public function classMap(array $classmap) + { + $this->classmap = $classmap; + + return $this; } - return $this; - } + /** + * Get the classmap + * + * @return array + */ + public function getClassmap() + { + $classmap = $this->classmap; + $classes = []; + + if (!empty($classmap)) { + foreach ($classmap as $class) { + // Can't use end because of strict mode :( + $name = current(array_slice(explode('\\', $class), -1, 1, true)); + + $classes[$name] = $class; + } + } + + return $classes; + } + + /** + * Set the extra options on the SoapClient + * + * @param array $options + * + * @return $this + */ + public function options(array $options) + { + $this->options = $options; + + return $this; + } + + /** + * Get the extra options + * + * @return array + */ + public function getOptions() + { + $options = [ + 'trace' => $this->getTrace(), + 'cache_wsdl' => $this->getCache(), + 'classmap' => $this->getClassmap(), + ]; + + if ($this->certificate) { + $options['local_cert'] = $this->certificate; + } + + $this->options = array_merge($options, $this->options); + + return $this->options; + } + + /** + * Set the certificate location + * + * @param string $certificate + * + * @return $this + */ + public function certificate($certificate) + { + if ($certificate) { + $this->certificate = $certificate; + } + + return $this; + } /** * Get the headers @@ -252,39 +253,39 @@ public function getHeaders() return $this->headers; } - /** - * Create a new SoapHeader - * - * @param string $namespace - * @param string $name - * @param null $data - * @param bool $mustUnderstand - * @param null $actor - * - * @return $this - */ - public function header($namespace, $name, $data = null, $mustUnderstand = false, $actor = null) - { - if ($actor) { - $this->headers[] = new SoapHeader($namespace, $name, $data, $mustUnderstand, $actor); - } else { - $this->headers[] = new SoapHeader($namespace, $name, $data, $mustUnderstand); + /** + * Create a new SoapHeader + * + * @param string $namespace + * @param string $name + * @param null $data + * @param bool $mustUnderstand + * @param null $actor + * + * @return $this + */ + public function header($namespace, $name, $data = null, $mustUnderstand = false, $actor = null) + { + if ($actor) { + $this->headers[] = new SoapHeader($namespace, $name, $data, $mustUnderstand, $actor); + } else { + $this->headers[] = new SoapHeader($namespace, $name, $data, $mustUnderstand); + } + + return $this; } - return $this; - } - - /** - * Set the Soap headers - * - * @param SoapHeader $header - * - * @return $this - */ - public function customHeader($header) - { - $this->headers[] = $header; - - return $this; - } + /** + * Set the Soap headers + * + * @param SoapHeader $header + * + * @return $this + */ + public function customHeader($header) + { + $this->headers[] = $header; + + return $this; + } } diff --git a/src/Artisaninweb/SoapWrapper/ServiceFactory.php b/src/Artisaninweb/SoapWrapper/ServiceFactory.php new file mode 100644 index 0000000..6546eef --- /dev/null +++ b/src/Artisaninweb/SoapWrapper/ServiceFactory.php @@ -0,0 +1,12 @@ +app['config']['soapwrapper'])) { + $this->app[SoapWrapperContract::class]->addByArray($soapWrapperConfig); + } + } - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - $soapWrapper = new SoapWrapper(); + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + $this->app->bindIf( + ServiceFactoryContract::class, + ServiceFactory::class + ); - if (is_array($this->app['config']['soapwrapper'])) { - $soapWrapper->addByArray($this->app['config']['soapwrapper']); + $this->app->singleton( + SoapWrapperContract::class, + function ($app) { + return new SoapWrapper($app[ServiceFactoryContract::class]); + } + ); } - - $this->app->bindIf(SoapWrapper::class, function () use ($soapWrapper) { - return $soapWrapper; - }); - } } diff --git a/src/Artisaninweb/SoapWrapper/SoapClientDecorator.php b/src/Artisaninweb/SoapWrapper/SoapClientDecorator.php new file mode 100644 index 0000000..0eb2d11 --- /dev/null +++ b/src/Artisaninweb/SoapWrapper/SoapClientDecorator.php @@ -0,0 +1,98 @@ +client = $wsdl; + } else { + $this->client = new SoapClient($wsdl, $options); + } + + if (!empty($headers)) { + $this->client->__setSoapHeaders($headers); + } + } + + public function getFunctions() + { + return $this->client->__getFunctions(); + } + + public function getLastRequest() + { + return $this->client->__getLastRequest(); + } + + public function getLastResponse() + { + return $this->client->__getLastResponse(); + } + + public function getLastRequestHeaders() + { + return $this->client->__getLastRequestHeaders(); + } + + public function getLastResponseHeaders() + { + return $this->client->__getLastResponseHeaders(); + } + + public function getTypes() + { + return $this->client->__getTypes(); + } + + public function getCookies() + { + return $this->client->__getCookies(); + } + + public function cookie($name, $value) + { + $this->client->__setCookie($name, $value); + + return $this; + } + + public function location($location = '') + { + $this->client->__setLocation($location); + + return $this; + } + + public function doRequest($request, $location, $action, $version, $one_way) + { + return $this->client->__doRequest($request, $location, $action, $version, $one_way); + } + + public function call($function, $params) + { + return call_user_func_array([$this, $function], $params); + } + + public function SoapCall( + $function, + array $params, + array $options = null, + $inputHeader = null, + &$outputHeaders = null + ) { + return $this->client->__soapCall($function, $params, $options, $inputHeader, $outputHeaders); + } +} diff --git a/src/Artisaninweb/SoapWrapper/SoapWrapper.php b/src/Artisaninweb/SoapWrapper/SoapWrapper.php index 9c611e1..7ce105c 100644 --- a/src/Artisaninweb/SoapWrapper/SoapWrapper.php +++ b/src/Artisaninweb/SoapWrapper/SoapWrapper.php @@ -2,113 +2,128 @@ namespace Artisaninweb\SoapWrapper; +use Artisaninweb\SoapWrapper\Contracts\Service as ServiceContract; +use Artisaninweb\SoapWrapper\Contracts\SoapWrapper as SoapWrapperContract; use Closure; -use SoapClient; +use Artisaninweb\SoapWrapper\Contracts\ServiceFactory as ServiceFactoryContract; +use Artisaninweb\SoapWrapper\Contracts\SoapClientDecorator as SoapClientDecoratorContract; use Artisaninweb\SoapWrapper\Exceptions\ServiceNotFound; use Artisaninweb\SoapWrapper\Exceptions\ServiceAlreadyExists; use Artisaninweb\SoapWrapper\Exceptions\ServiceMethodNotExists; -class SoapWrapper +class SoapWrapper implements SoapWrapperContract { - /** - * @var array - */ - protected $services; - - /** - * SoapWrapper constructor - */ - public function __construct() - { - $this->services = []; - } - - /** - * Add a new service to the wrapper - * - * @param string $name - * @param Closure $closure - * - * @return $this - * @throws ServiceAlreadyExists - */ - public function add($name, Closure $closure) - { - if (!$this->has($name)) { - $service = new Service(); - - $closure($service); - - $this->services[$name] = $service; - - return $this; + /** + * @var array + */ + protected $services; + + /** + * @var ServiceFactoryContract + */ + private $serviceFactory; + + /** + * SoapWrapper constructor + */ + public function __construct( + ServiceFactoryContract $serviceFactory + ) { + $this->serviceFactory = $serviceFactory; + + $this->services = []; } - throw new ServiceAlreadyExists("Service '" . $name . "' already exists."); - } - - /** - * Add services by array - * - * @param array $services - * - * @return $this - * - * @throws ServiceAlreadyExists - * @throws ServiceMethodNotExists - */ - public function addByArray(array $services = []) - { - if (!empty($services)) { - foreach ($services as $name => $methods) { + /** + * Add a new service to the wrapper + * + * @param string $name + * @param Closure $closure + * + * @return $this + * @throws ServiceAlreadyExists + */ + public function add($name, Closure $closure) + { if (!$this->has($name)) { - $service = new Service(); + $service = $this->serviceFactory->createNew(); - foreach ($methods as $method => $value) { - if (method_exists($service, $method)) { - $service->{$method}($value); - } else { - throw new ServiceMethodNotExists(sprintf( - "Method '%s' does not exists on the %s service.", - $method, - $name - )); - } - } + $closure($service); - $this->services[$name] = $service; + $this->services[$name] = $service; - continue; + return $this; } - throw new ServiceAlreadyExists(sprintf( - "Service '%s' already exists.", - $name - )); - } + throw new ServiceAlreadyExists("Service '" . $name . "' already exists."); } - return $this; - } - - /** - * Get the client - * - * @param string $name - * @param Closure $closure - * - * @return mixed - * @throws ServiceNotFound - */ + /** + * Add services by array + * + * @param array $services + * + * @return $this + * + * @throws ServiceAlreadyExists + * @throws ServiceMethodNotExists + */ + public function addByArray(array $services = []) + { + if (!empty($services)) { + foreach ($services as $name => $methods) { + if (!$this->has($name)) { + $service = $this->serviceFactory->createNew(); + + foreach ($methods as $method => $value) { + if (method_exists($service, $method)) { + $service->{$method}($value); + } else { + throw new ServiceMethodNotExists( + sprintf( + "Method '%s' does not exists on the %s service.", + $method, + $name + ) + ); + } + } + + $this->services[$name] = $service; + + continue; + } + + throw new ServiceAlreadyExists( + sprintf( + "Service '%s' already exists.", + $name + ) + ); + } + } + + return $this; + } + + /** + * Get the client + * + * @param string $name + * @param Closure $closure + * + * @return mixed + * @throws ServiceNotFound + */ public function client($name, Closure $closure = null) { if ($this->has($name)) { /** @var Service $service */ - $service = $this->services[$name]; + $service = $this->getService($name); if (is_null($service->getClient())) { - $client = new Client($service->getWsdl(), $service->getOptions(), $service->getHeaders()); - + $client = new SoapClientDecorator($service->getWsdl(), $service->getOptions(), $service->getHeaders()); + $service->client($client); } else { $client = $service->getClient(); @@ -120,33 +135,42 @@ public function client($name, Closure $closure = null) throw new ServiceNotFound("Service '" . $name . "' not found."); } - /** - * A easy access call method - * - * @param string $call - * @param array $data - * - * @return mixed - */ - public function call($call, $data = [], $options = []) - { - list($name, $function) = explode('.', $call, 2); - - return $this->client($name, function ($client) use ($function, $data, $options) { - /** @var Client $client */ - return $client->SoapCall($function, $data, $options); - }); - } - - /** - * Check if wrapper has service - * - * @param string $name - * - * @return bool - */ - public function has($name) - { - return (array_key_exists($name, $this->services)); - } + /** + * A easy access call method + * + * @param string $call + * @param array $data + * + * @return mixed + */ + public function call($call, $data = [], $options = []) + { + list($name, $function) = explode('.', $call, 2); + + return $this->client($name, function ($client) use ($function, $data, $options) { + /** @var SoapClientDecoratorContract $client */ + return $client->SoapCall($function, $data, $options); + }); + } + + /** + * Check if wrapper has service + * + * @param string $name + * + * @return bool + */ + public function has($name) + { + return (array_key_exists($name, $this->services)); + } + + /** + * @param $name + * @return ServiceContract + */ + public function getService($name) + { + return data_get($this->services, $name, null); + } }