1. Go to this page and download the library: Download webit/soap-api library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
webit / soap-api example snippets
namespace Webit\SoapApi\Features\Ip2Geo;
use Webit\SoapApi\Executor\SoapApiExecutor;
class Ip2GeoSimpleClient
{
/** @var SoapApiExecutor */
private $executor;
/**
* @param SoapApiExecutor $executor
*/
public function __construct(SoapApiExecutor $executor)
{
$this->executor = $executor;
}
/**
* @param Ip $ip
* @return GeoLocation
*/
public function getGeoLocation(Ip $ip)
{
$result = $this->executor->executeSoapFunction(
'ResolveIP',
array(
'ipAddress' => $ip,
'licenseKey' => ''
)
);
return $this->hydrateToGeoLocation($result);
}
/**
* @param $result
* @return null|GeoLocation
*/
private function hydrateToGeoLocation($result)
{
$result = isset($result->ResolveIPResult) ? $result->ResolveIPResult : null;
if (! $result) {
return null;
}
return new GeoLocation(
$result->City,
$result->StateProvince,
$result->Country,
$result->Organization,
$result->Latitude,
$result->Longitude,
$result->AreaCode,
$result->TimeZone,
$result->HasDaylightSavings,
$result->Certainty,
$result->RegionName,
$result->CountryCode
);
}
}
// IP address wrapper
class Ip
{
/** @var string */
private $ip;
public function __construct($ip)
{
$this->ip = $ip;
}
public function __toString()
{
return (string) $this->ip;
}
}
use Webit\SoapApi\Executor\SoapApiExecutorBuilder;
use Webit\SoapApi\SoapClient\SoapClientSimpleFactory;
$builder = SoapApiExecutorBuilder::create();
$builder->setWsdl('http://ws.cdyne.com/ip2geo/ip2geo.asmx?WSDL');
$client = new \Webit\SoapApi\Features\Ip2Geo\Ip2GeoSimpleClient(
$builder->build()
);
$result = $client->getGeoLocation(new Ip('8.8.8.8')); // returns GeoLocation instance
namespace Webit\SoapApi\Features\Ip2Geo\Normaliser;
use Webit\SoapApi\Features\Ip2Geo\Ip;
use Webit\SoapApi\Input\Exception\NormalisationException;
use Webit\SoapApi\Input\InputNormaliser;
class ResolveIPNormaliser implements InputNormaliser
{
/**
* @param string $soapFunction
* @param mixed $arguments
* @throws NormalisationException
* @return array
*/
public function normaliseInput($soapFunction, $arguments)
{
if (! ($arguments instanceof Ip)) {
throw new NormalisationException(__CLASS__ . '
namespace Webit\SoapApi\Features\Ip2Geo;
use Webit\SoapApi\Executor\SoapApiExecutor;
class Ip2GeoInputNormalisingClient
{
/** @var SoapApiExecutor */
private $executor;
public function __construct(SoapApiExecutor $executor)
{
$this->executor = $executor;
}
/**
* @param Ip $ip
* @return GeoLocation
*/
public function getGeoLocation(Ip $ip)
{
$result = $this->executor->executeSoapFunction('ResolveIP', $ip);
return $this->hydrateToGeoLocation($result);
}
public function hydrateToGeoLocation($result)
{
// same as Ip2GeoSimpleClient
}
}
use Webit\SoapApi\Executor\SoapApiExecutorBuilder;
use Webit\SoapApi\SoapClient\SoapClientSimpleFactory;
$builder = SoapApiExecutorBuilder::create();
$builder->setWsdl('http://ws.cdyne.com/ip2geo/ip2geo.asmx?WSDL');
$builder->setInputNormaliser(
new \Webit\SoapApi\Input\FrontInputNormaliser(
array(
'ResolveIP' => new ResolveIPNormaliser()
)
)
);
$client = new \Webit\SoapApi\Features\Ip2Geo\Ip2GeoInputNormalisingClient(
$builder->build()
);
$result = $client->getGeoLocation(new Ip('8.8.8.8')); // returns GeoLocation instance
namespace Webit\SoapApi\Features\Ip2Geo\Hydrator;
use Webit\SoapApi\Features\Ip2Geo\GeoLocation;
use Webit\SoapApi\Hydrator\Hydrator;
class ResolveIPHydrator implements Hydrator
{
/**
* @param \stdClass|array $result
* @param string $soapFunction
* @return mixed
*/
public function hydrateResult($result, $soapFunction)
{
$result = isset($result->ResolveIPResult) ? $result->ResolveIPResult : null;
if (! $result) {
return null;
}
return new GeoLocation(
$result->City,
$result->StateProvince,
$result->Country,
$result->Organization,
$result->Latitude,
$result->Longitude,
$result->AreaCode,
$result->TimeZone,
$result->HasDaylightSavings,
$result->Certainty,
$result->RegionName,
$result->CountryCode
);
}
}
namespace Webit\SoapApi\Features\Ip2Geo;
use Webit\SoapApi\Executor\SoapApiExecutor;
class Ip2GeoResultHydratingClient
{
/** @var SoapApiExecutor */
private $executor;
public function __construct(SoapApiExecutor $executor)
{
$this->executor = $executor;
}
/**
* @param Ip $ip
* @return GeoLocation
*/
public function getGeoLocation(Ip $ip)
{
return $this->executor->executeSoapFunction('ResolveIP', $ip);
}
}
use Webit\SoapApi\Executor\SoapApiExecutorBuilder;
use Webit\SoapApi\SoapClient\SoapClientSimpleFactory;
$builder = SoapApiExecutorBuilder::create();
$builder->setWsdl('http://ws.cdyne.com/ip2geo/ip2geo.asmx?WSDL');
$builder->setInputNormaliser(
new \Webit\SoapApi\Input\FrontInputNormaliser(
array(
'ResolveIP' => new ResolveIPNormaliser()
)
)
);
$builder->setHydrator(
new \Webit\SoapApi\Hydrator\FrontHydrator(
array(
'ResolveIP' => new ResolveIPHydrator()
)
)
);
$client = new \Webit\SoapApi\Features\Ip2Geo\Ip2GeoResultHydratingClient(
$builder->build()
);
$result = $client->getGeoLocation(new Ip('8.8.8.8')); // returns GeoLocation instance
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.