Skip to content

Commit

Permalink
Add the ability to select specific services by port / service name
Browse files Browse the repository at this point in the history
  • Loading branch information
veewee committed Nov 14, 2024
1 parent 98f6257 commit 222a282
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"php-soap/engine": "^2.13.0",
"php-soap/encoding": "~0.13",
"php-soap/psr18-transport": "^1.7",
"php-soap/wsdl-reader": "~0.18",
"php-soap/wsdl-reader": "~0.19",
"psr/event-dispatcher": "^1.0",
"psr/log": "^1.0 || ^2.0 || ^3.0",
"symfony/console": "~5.4 || ~6.0 || ~7.0",
Expand Down
8 changes: 7 additions & 1 deletion docs/cli/generate-clientfactory.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ use Soap\Encoding\EncoderRegistry;
use Soap\Psr18Transport\Psr18Transport;
use Soap\Psr18Transport\Wsdl\Psr18Loader;
use Soap\Wsdl\Loader\FlatteningLoader;
use Soap\WsdlReader\Locator\ServiceSelectionCriteria
use Soap\WsdlReader\Model\Definitions\SoapVersion;
use Symfony\Component\Cache\Adapter\RedisAdapter;
use Symfony\Component\EventDispatcher\EventDispatcher;
Expand Down Expand Up @@ -77,7 +78,12 @@ class CalculatorClientFactory
new RedisAdapter(RedisAdapter::createConnection('redis://localhost')),
new CacheConfig('my-wsdl-cache-key', ttlInSeconds: 3600)
)
->withPreferredSoapVersion(SoapVersion::SOAP_12)
->withWsdlServiceSelectionCriteria(
ServiceSelectionCriteria::defaults()
->withPreferredSoapVersion(SoapVersion::SOAP_12)
->withServiceName('SpecificServiceName')
->withPortName('SpecificPortName')
)
);

$eventDispatcher = new EventDispatcher();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ClientFactoryGenerator implements GeneratorInterface
// ->withTransport()
// If you want specific SOAP setting:
// ->withWsdlParserContext()
// ->withPreferredSoapVersion()
// ->withWsdlServiceSelectionCriteria()
);
\$eventDispatcher = new EventDispatcher();
Expand Down
25 changes: 9 additions & 16 deletions src/Phpro/SoapClient/Soap/EngineOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ final class EngineOptions
private ?Transport $transport = null;
private ?CacheItemPoolInterface $cache = null;
private ?CacheConfig $cacheConfig = null;
private ?SoapVersion $preferredSoapVersion = null;
private ?ParserContext $wsdlParserContext = null;
private ?EncoderRegistry $encoderRegistry = null;

private ?ServiceSelectionCriteria $wsdlServiceSelectionCriteria = null;

/**
* @param non-empty-string $wsdl
*/
Expand Down Expand Up @@ -81,18 +82,18 @@ public function withTransport(Transport $transport): self
return $clone;
}

public function withPreferredSoapVersion(SoapVersion $preferredSoapVersion): self
public function withEncoderRegistry(EncoderRegistry $registry): self
{
$clone = clone $this;
$clone->preferredSoapVersion = $preferredSoapVersion;
$clone->encoderRegistry = $registry;

return $clone;
}

public function withEncoderRegistry(EncoderRegistry $registry): self
public function withWsdlServiceSelectionCriteria(ServiceSelectionCriteria $criteria): self
{
$clone = clone $this;
$clone->encoderRegistry = $registry;
$clone->wsdlServiceSelectionCriteria = $criteria;

return $clone;
}
Expand Down Expand Up @@ -133,19 +134,11 @@ public function getCacheConfig(): CacheConfig
return $this->cacheConfig ?? new CacheConfig('soap-engine-'.md5($this->wsdl));
}

/**
* @return Option<SoapVersion>
*/
public function getPreferredSoapVersion(): Option
{
return from_nullable($this->preferredSoapVersion);
}

public function getWsdlServiceSelectionCriteria(): ServiceSelectionCriteria
{
return ServiceSelectionCriteria::defaults()
->withAllowHttpPorts(false)
->withPreferredSoapVersion($this->preferredSoapVersion);
return ($this->wsdlServiceSelectionCriteria ?? ServiceSelectionCriteria::defaults())
// HTTP ports are not supported in this SOAP-client
->withAllowHttpPorts(false);
}

public function getEncoderRegistry(): EncoderRegistry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static function factory(string \$wsdl) : \App\Client\Myclient
// ->withTransport()
// If you want specific SOAP setting:
// ->withWsdlParserContext()
// ->withPreferredSoapVersion()
// ->withWsdlServiceSelectionCriteria()
);
\$eventDispatcher = new EventDispatcher();
Expand Down

0 comments on commit 222a282

Please sign in to comment.