Classe de découverte service
This commit is contained in:
parent
4761f02b4a
commit
fa4d038078
94
library/ServiceTest/ServiceDiscover.php
Normal file
94
library/ServiceTest/ServiceDiscover.php
Normal file
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
require_once('Zend/Soap/Client.php');
|
||||
|
||||
class ServiceDiscover {
|
||||
|
||||
protected $serviceWsdl = null;
|
||||
protected $serviceOptions = array();
|
||||
protected $serviceStructure = array();
|
||||
protected $serviceStructureTypes = array();
|
||||
protected $serviceTypes;
|
||||
protected $serviceFunctions;
|
||||
|
||||
|
||||
public function __construct($wsdl, $options = array())
|
||||
{
|
||||
$this->serviceWsdl = $wsdl;
|
||||
$this->serviceOptions = $options;
|
||||
$this->setStructure();
|
||||
}
|
||||
|
||||
public function getStructure()
|
||||
{
|
||||
return $this->serviceStructure;
|
||||
}
|
||||
|
||||
public function getStructureParam()
|
||||
{
|
||||
return $this->serviceStructureTypes;
|
||||
}
|
||||
|
||||
protected function setStructure()
|
||||
{
|
||||
$client = new Zend_Soap_Client(
|
||||
$this->serviceWsdl,
|
||||
$this->serviceOptions
|
||||
);
|
||||
$this->serviceFunctions = $client->getFunctions();
|
||||
$this->serviceTypes = $client->getTypes();
|
||||
|
||||
foreach($this->serviceFunctions as $func)
|
||||
{
|
||||
$this->setFunction($func);
|
||||
}
|
||||
|
||||
foreach($this->serviceTypes as $type){
|
||||
$this->setType($type);
|
||||
}
|
||||
}
|
||||
|
||||
protected function setFunction($func)
|
||||
{
|
||||
if (preg_match('/[^\s]+\s([^\s]+)\((.*)\)/', $func, $matches))
|
||||
{
|
||||
$funcName = $matches[1];
|
||||
$funcParams = $matches[2];
|
||||
$this->serviceStructure[$funcName] = array();
|
||||
if (preg_match_all('/([^\s]+)\s([^\s]+),?/', $funcParams, $mParams))
|
||||
{
|
||||
$nbParams = count($mParams[0]);
|
||||
for($i=0;$i<$nbParams;$i++)
|
||||
{
|
||||
$type = $mParams[1][$i];
|
||||
$name = $mParams[2][$i];
|
||||
$this->serviceStructure[$funcName][$i] = array(
|
||||
'name' => $name,
|
||||
'type' => $type
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function setType($type)
|
||||
{
|
||||
$type = str_replace("\n", '', $type);
|
||||
if (preg_match('/struct\s([^\s]+)\s\{(.*)\}$/m', $type, $matches))
|
||||
{
|
||||
$struct = trim($matches[1]);
|
||||
$params = trim($matches[2]);
|
||||
preg_match_all('/([^\s]+)\s([^\s]+);/', $params, $paramsMatches);
|
||||
$nbParams = count($paramsMatches[0]);
|
||||
$this->serviceStructureTypes[$struct] = array();
|
||||
for($i=0; $i<$nbParams;$i++)
|
||||
{
|
||||
$this->serviceStructureTypes[$struct][$i] = array(
|
||||
'name' => $paramsMatches[2][$i],
|
||||
'type' => $paramsMatches[1][$i],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user