Skip to content
Snippets Groups Projects
Verified Commit 32c1248d authored by Bayu Samudra's avatar Bayu Samudra
Browse files

feat: adding example for soap

parent 230ce98e
No related merge requests found
......@@ -7,5 +7,5 @@ POSTGRES_USER=postgres
POSTGRES_PASSWORD=root
API_KEY=secret
REST_HOST=http://webtune-rest:8888
REST_HOST=http://webtune-soap:8080/webtune-soap
REST_KEY=apahayo
\ No newline at end of file
<?php
namespace Service\Soap;
use Service\Soap\TokenSoap;
use SoapClient;
use SoapHeader;
class SoapClientFactory {
private string $wsdl;
private TokenSoap $token_gen;
public function __construct(string $wsdl) {
$this->wsdl = $wsdl;
$this->token_gen = new TokenSoap();
}
public function generate_client(?string $token = null): SoapClient {
$client = new SoapClient($this->wsdl);
if(is_null($token)){
$token = $this->token_gen->generate_token();
}
$header = new SoapHeader(
"http://services.webtune.com/",
"Token",
$token
);
$client->__setSoapHeaders($header);
return $client;
}
}
\ No newline at end of file
<?php
namespace Service\Soap;
class SubscribeSoap {
private SoapClientFactory $factory;
public function __construct() {
$wsdl = getenv("SOAP_API"). "/services/subscription?wsdl";
$this->factory = new SoapClientFactory($wsdl);
}
public function is_access_permitted(
string $creator_id,
string $subscriber_id,
?string $last_token = null
): bool {
$soap = $this->factory->generate_client($last_token);
return $soap->__soapCall(
"isPermittedAccess",
[
"creator-id" => $creator_id,
"subscriber-id" => $subscriber_id,
]
);
}
}
<?php
namespace Service\Soap;
use SoapClient;
class TokenSoap {
private SoapClient $soap;
static string | null $token;
static int $exp_time;
public function __construct() {
$soap_key = getenv("SOAP_KEY");
$wsdl = getenv("SOAP_API")."/services/security?wsdl";
$this->soap = new SoapClient($wsdl, [
"stream_context" => stream_context_create([
"http" => [
"header" => "X-API-KEY: $soap_key",
],
]),
]);
}
public function generate_token(): string {
$token = $this->soap->__soapCall(
"getToken",
[]
);
return $token;
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment