Skip to content

Commit

Permalink
Merge pull request #1 from rocketlatotzky/upgrade-to-wsdlcreator-david
Browse files Browse the repository at this point in the history
updated to new wsdl-creator.
  • Loading branch information
alibo authored Sep 20, 2018
2 parents c4294a8 + 35d6ecc commit 2dd487b
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 402 deletions.
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
"type": "library",
"minimum-stability": "stable",
"require": {
"php": ">=5.4.0",
"php": ">=7.1.0",
"ext-soap": "*",
"piotrooo/wsdl-creator": "1.*"
"ext-dom": "*",
"piotrooo/wsdl-creator": "2.0.*"
},
"autoload": {
"psr-4": {
Expand All @@ -37,6 +38,7 @@
},
"require-dev": {
"phpspec/phpspec": "^2.2",
"phpunit/phpunit": "4.*",
"codeception/codeception": "2.0.*"
}
}
148 changes: 132 additions & 16 deletions src/SamanUssd.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,52 @@
use Nikapps\SamanUssd\Contracts\SamanUssdListener;
use Nikapps\SamanUssd\Soap\SamanSoapServer;
use SoapServer;
use WSDL\WSDLCreator;
use WSDL\Annotation\BindingType;
use WSDL\Annotation\SoapBinding;
use WSDL\Builder\AnnotationWSDLBuilder;
use WSDL\Builder\Method;
use WSDL\Builder\Parameter;
use WSDL\Builder\WSDLBuilder;
use WSDL\Lexer\Tokenizer;
use WSDL\WSDL;

class SamanUssd
{
/**
* If disabled, annotations in soapApiClass are ignored.
* @var bool
*/
public $useAnnotions = false;

/**
* @var string
*/
protected $soapApiClass = '\Nikapps\SamanUssd\Soap\SamanSoapServer';

/**
* Ignored if useAnnotions = true
* @var string
*/
protected $endpoint = 'http://example.com/webservice';

/**
* Ignored if useAnnotions = true
* @var string
*/
protected $namespace = 'http://example.com';

/**
* Ignored if useAnnotions = true
* @var string
*/
protected $targetNamespace = 'http://example.com/types';

/**
* Ignored if useAnnotions = true
* @var string
*/
protected $name = 'saman-ussd';

/**
* @var string
*/
Expand Down Expand Up @@ -54,16 +81,92 @@ class SamanUssd
*/
public function handle()
{
$wsdl = new WSDLCreator($this->soapApiClass, $this->endpoint);
$wsdl->setNamespace($this->namespace);

isset($_GET[$this->wsdlQueryString])
? $wsdl->renderWSDL()
: $this->setupSoapServer($wsdl);
if ($this->useAnnotions) {
$builder =(new AnnotationWSDLBuilder($this->soapApiClass))->build()->getBuilder();
} else {
$builder = WSDLBuilder::instance()
->setName($this->name)
->setTargetNamespace($this->targetNamespace)
->setNs($this->namespace)
->setLocation($this->endpoint)
->setStyle(SoapBinding::RPC)
->setUse(SoapBinding::LITERAL)
->setSoapVersion(BindingType::SOAP_11)
->setMethods($this->getMethods());
}

$wsdl = WSDL::fromBuilder($builder);

if (isset($_GET[$this->wsdlQueryString]))
{
echo $wsdl->create();
} else
{
$this->setupSoapServer(
$builder->getNs() . strtolower(ltrim(str_replace('\\', '/', $this->soapApiClass), '/')),
$builder->getLocation()
);
}
}

/**
* Set soap api class
* Method definion (if not using annotations)
*
* @return array
* @throws \Exception
*/
private function getMethods() {
$tokenizer = new Tokenizer();

$meths=[];
/**
* public function GetProductInfo
*/
$parameters1 = [
Parameter::fromTokens($tokenizer->lex('string $productCode')),
Parameter::fromTokens($tokenizer->lex('string $languageCode'))
];
$return1 = Parameter::fromTokens($tokenizer->lex('string $Result'));
$meths[] = new Method('GetProductInfo', $parameters1, $return1);
/**
* public function CallSaleProvider
*
*/

$parameters2 = [
Parameter::fromTokens($tokenizer->lex('string $productCode')),
Parameter::fromTokens($tokenizer->lex('int $Amount')),
Parameter::fromTokens($tokenizer->lex('string $CellNumber')),
Parameter::fromTokens($tokenizer->lex('long $SEPId')),
Parameter::fromTokens($tokenizer->lex('string $languageCode'))
];
$return2 = Parameter::fromTokens($tokenizer->lex('string $Result'));
$meths[] = new Method('CallSaleProvider', $parameters2, $return2);
/*
* public function ExecSaleProvider
*/

$parameters3 = [Parameter::fromTokens($tokenizer->lex('string $ProviderID'))];
$return3 = Parameter::fromTokens($tokenizer->lex('string $Result'));
$meths[] = new Method('ExecSaleProvider', $parameters3, $return3);

/**
* public function CheckStatus
*/
$parameters4 = [Parameter::fromTokens($tokenizer->lex('string $ProviderID'))];
$return4 = Parameter::fromTokens($tokenizer->lex('string $Result'));
$meths[] = new Method('CheckStatus', $parameters4, $return4);

return $meths;
}
/**
* Set soap api class.
*
* IF $this->useAnnotations = true, THEN annotations in $soapApiClass WILL override
* $this->name, $this->targetNamespace, $this->namespace and $this->endpoint.
*
* To ignore annotation in $soapApiClass, set $this->useAnnotations = false.
*
* @param string $soapApiClass
* @return $this
Expand All @@ -76,7 +179,7 @@ public function setSoapApiClass($soapApiClass)
}

/**
* Set api endpoint
* Set api endpoint (if not using annotations)
*
* @param string $endpoint
* @return $this
Expand All @@ -89,7 +192,7 @@ public function endpoint($endpoint)
}

/**
* Set namespace
* Set namespace (if not using annotations)
*
* @param string $namespace
* @return $this
Expand All @@ -101,6 +204,20 @@ public function setNamespace($namespace)
return $this;
}

/**
* Set target-namespace (if not using annotations)
*
* @param string $namespace
* @return $this
*/
public function setTargetNamespace($namespace)
{
$this->targetNamespace = $namespace;

return $this;
}


/**
* Set wsdl query string
*
Expand Down Expand Up @@ -191,20 +308,19 @@ public function onCheckStatus(\Closure $callback)
}

/**
* Setup soap server
*
* @param WSDLCreator $wsdl
* @param string $uri
* @param string $location
*/
protected function setupSoapServer(WSDLCreator $wsdl)
protected function setupSoapServer(string $uri, string $location)
{
$request = file_get_contents('php://input');

$server = new SoapServer(
$this->endpoint . '?' . $this->wsdlQueryString,
$location . '?' . $this->wsdlQueryString,
array_merge([
'uri' => $wsdl->getNamespaceWithSanitizedClass(),
'uri' => $uri,
'cache_wsdl' => WSDL_CACHE_NONE,
'location' => $wsdl->getLocation(),
'location' => $location,
'style' => SOAP_RPC,
'use' => SOAP_LITERAL
], $this->options)
Expand Down
88 changes: 74 additions & 14 deletions src/Soap/SamanSoapServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,25 @@

use Nikapps\SamanUssd\Contracts\SamanSoapApi;
use Nikapps\SamanUssd\Contracts\SamanUssdListener;
use WSDL\Annotation\BindingType;
use WSDL\Annotation\SoapBinding;
use WSDL\Annotation\WebMethod;
use WSDL\Annotation\WebParam;
use WSDL\Annotation\WebResult;
use WSDL\Annotation\WebService;

/**
* Class SamanSoapServer
*
* @WebService(
* name="SamanSoapServer",
* targetNamespace="saman-ussd.dev/nikapps/samanussd/soap/samansoapserver",
* location="http://saman-ussd.dev/tests/api/webservice.php",
* ns="saman-ussd.dev/nikapps/samanussd/soap/samansoapserver/types"
* )
* @BindingType(value="SOAP_11")
* @SoapBinding(style="RPC", use="LITERAL")
*/
class SamanSoapServer implements SamanSoapApi
{
/**
Expand Down Expand Up @@ -44,9 +62,19 @@ public function setListener($listener)
/**
* Get product info
*
* @WebMethod
* @param string $productCode
* @param string $languageCode
* @WSDL\Annotation\WebMethod
*
* @WSDL\Annotation\WebParam(
* param="string $productCode"
* )
*
* @WSDL\Annotation\WebParam(
* param="string $languageCode"
* )
*
* @WSDL\Annotation\WebResult(
* param="string $Result"
* )
* @return string $Result
*/
public function GetProductInfo($productCode, $languageCode)
Expand All @@ -65,13 +93,31 @@ public function GetProductInfo($productCode, $languageCode)
/**
* Notify sale provider
*
* @WebMethod
* @param string $productCode
* @param int $Amount
* @param string $CellNumber
* @param long $SEPId
* @param string $languageCode
* @return string $Result
* @WSDL\Annotation\WebMethod
*
* @WSDL\Annotation\WebParam(
* param="string $productCode"
* )
*
* @WSDL\Annotation\WebParam(
* param="int $Amount"
* )
*
* @WSDL\Annotation\WebParam(
* param="string $CellNumber"
* )
*
* @WSDL\Annotation\WebParam(
* param="long $SEPId"
* )
*
* @WSDL\Annotation\WebParam(
* param="string $languageCode"
* )
*
* @WSDL\Annotation\WebResult(
* param="string $Result"
* )
*/
public function CallSaleProvider(
$productCode,
Expand Down Expand Up @@ -103,8 +149,15 @@ public function CallSaleProvider(
/**
* Confirm payment
*
* @WebMethod
* @param string $ProviderID
* @WSDL\Annotation\WebMethod
*
* @WSDL\Annotation\WebParam(
* param="string $ProviderID"
* )
*
* @WSDL\Annotation\WebResult(
* param="string $Result"
* )
* @return string $Result
*/
public function ExecSaleProvider($ProviderID)
Expand All @@ -119,8 +172,15 @@ public function ExecSaleProvider($ProviderID)
/**
* Check status of transaction
*
* @WebMethod
* @param string $ProviderID
* @WSDL\Annotation\WebMethod
*
* @WSDL\Annotation\WebParam(
* param="string $ProviderID"
* )
*
* @WSDL\Annotation\WebResult(
* param="string $Result"
* )
* @return string $Result
*/
public function CheckStatus($ProviderID)
Expand Down
Loading

0 comments on commit 2dd487b

Please sign in to comment.