Rewrited Definition of WebService and WSDL dumper
This commit is contained in:
148
src/BeSimple/SoapCommon/Definition/Definition.php
Normal file
148
src/BeSimple/SoapCommon/Definition/Definition.php
Normal file
@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the BeSimpleSoap.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
* (c) Francis Besset <francis.besset@gmail.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace BeSimple\SoapCommon\Definition;
|
||||
|
||||
use BeSimple\SoapCommon\Definition\Type\TypeRepository;
|
||||
|
||||
/**
|
||||
* @author Francis Besset <francis.besset@gmail.com>
|
||||
*/
|
||||
class Definition
|
||||
{
|
||||
protected $name;
|
||||
protected $namespace;
|
||||
|
||||
protected $typeRepository;
|
||||
|
||||
protected $options;
|
||||
protected $methods;
|
||||
|
||||
public function __construct($name, $namespace, TypeRepository $typeRepository, array $options = array())
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->namespace = $namespace;
|
||||
$this->methods = array();
|
||||
|
||||
$this->typeRepository = $typeRepository;
|
||||
|
||||
$this->setOptions($options);
|
||||
}
|
||||
|
||||
public function setOptions(array $options)
|
||||
{
|
||||
$this->options = array(
|
||||
'version' => \SOAP_1_1,
|
||||
'style' => \SOAP_RPC,
|
||||
'use' => \SOAP_LITERAL,
|
||||
'location' => null,
|
||||
);
|
||||
|
||||
$invalid = array();
|
||||
foreach ($options as $key => $value) {
|
||||
if (array_key_exists($key, $this->options)) {
|
||||
$this->options[$key] = $value;
|
||||
} else {
|
||||
$invalid[] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
if ($invalid) {
|
||||
throw new \InvalidArgumentException(sprintf('The Definition does not support the following options: "%s"', implode('", "', $invalid)));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setOption($key, $value)
|
||||
{
|
||||
if (!array_key_exists($key, $this->options)) {
|
||||
throw new \InvalidArgumentException(sprintf('The Definition does not support the "%s" option.', $key));
|
||||
}
|
||||
|
||||
$this->options[$key] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOption($key)
|
||||
{
|
||||
if (!array_key_exists($key, $this->options)) {
|
||||
throw new \InvalidArgumentException(sprintf('The Definition does not support the "%s" option.', $key));
|
||||
}
|
||||
|
||||
return $this->options[$key];
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getNamespace()
|
||||
{
|
||||
return $this->namespace;
|
||||
}
|
||||
|
||||
public function getType($phpType)
|
||||
{
|
||||
return $this->types[$phpType];
|
||||
}
|
||||
|
||||
public function addType($phpType, $xmlType)
|
||||
{
|
||||
if (isset($$this->types[$phpType])) {
|
||||
throw new \Exception();
|
||||
}
|
||||
|
||||
$this->types[$phpType] = $xmlType;
|
||||
}
|
||||
|
||||
public function getMessages()
|
||||
{
|
||||
$messages = array();
|
||||
foreach ($this->methods as $method) {
|
||||
$messages[] = $method->getHeaders();
|
||||
$messages[] = $method->getInput();
|
||||
$messages[] = $method->getOutput();
|
||||
}
|
||||
|
||||
return $messages;
|
||||
}
|
||||
|
||||
public function getMethod($name, $default = null)
|
||||
{
|
||||
return isset($this->methods[$name]) ? $this->methods[$name] : $default;
|
||||
}
|
||||
|
||||
public function getMethods()
|
||||
{
|
||||
return $this->methods;
|
||||
}
|
||||
|
||||
public function addMethod(Method $method)
|
||||
{
|
||||
$name = $method->getName();
|
||||
if (isset($this->methods[$name])) {
|
||||
throw new \Exception(sprintf('The method "%s" already exists', $name));
|
||||
}
|
||||
|
||||
$this->methods[$name] = $method;
|
||||
|
||||
return $method;
|
||||
}
|
||||
|
||||
public function getTypeRepository()
|
||||
{
|
||||
return $this->typeRepository;
|
||||
}
|
||||
}
|
61
src/BeSimple/SoapCommon/Definition/Message.php
Normal file
61
src/BeSimple/SoapCommon/Definition/Message.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the BeSimpleSoap.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
* (c) Francis Besset <francis.besset@gmail.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace BeSimple\SoapCommon\Definition;
|
||||
|
||||
use BeSimple\SoapCommon\Definition\Type\TypeInterface;
|
||||
|
||||
/**
|
||||
* @author Francis Besset <francis.besset@gmail.com>
|
||||
*/
|
||||
class Message
|
||||
{
|
||||
protected $name;
|
||||
protected $parts;
|
||||
|
||||
public function __construct($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->parts = array();
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function all()
|
||||
{
|
||||
return $this->parts;
|
||||
}
|
||||
|
||||
public function get($name, $default = null)
|
||||
{
|
||||
return isset($this->parts[$name]) ? $this->parts[$name] : $default;
|
||||
}
|
||||
|
||||
public function isEmpty()
|
||||
{
|
||||
return 0 === count($this->parts) ? true : false;
|
||||
}
|
||||
|
||||
public function add($name, $phpType, $nillable = false)
|
||||
{
|
||||
if ($phpType instanceof TypeInterface) {
|
||||
$phpType = $phpType->getPhpType();
|
||||
}
|
||||
|
||||
$this->parts[$name] = new Part($name, $phpType, $nillable);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
98
src/BeSimple/SoapCommon/Definition/Method.php
Normal file
98
src/BeSimple/SoapCommon/Definition/Method.php
Normal file
@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the BeSimpleSoap.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
* (c) Francis Besset <francis.besset@gmail.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace BeSimple\SoapCommon\Definition;
|
||||
|
||||
use BeSimple\SoapCommon\Definition\Type\TypeRepository;
|
||||
|
||||
/**
|
||||
* @author Francis Besset <francis.besset@gmail.com>
|
||||
*/
|
||||
class Method
|
||||
{
|
||||
private $name;
|
||||
|
||||
private $headers;
|
||||
private $input;
|
||||
private $output;
|
||||
private $fault;
|
||||
|
||||
public function __construct($name, TypeRepository $typeRepository)
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
$this->headers = new Message($name.'Header', $typeRepository);
|
||||
$this->input = new Message($name.'Request', $typeRepository);
|
||||
$this->output = new Message($name.'Response', $typeRepository);
|
||||
$this->fault = new Message($name.'Fault', $typeRepository);
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getDefinition()
|
||||
{
|
||||
return $this->definition;
|
||||
}
|
||||
|
||||
public function getVersions()
|
||||
{
|
||||
return array(\SOAP_1_1, \SOAP_1_2);
|
||||
}
|
||||
|
||||
public function getUse()
|
||||
{
|
||||
return \SOAP_LITERAL;
|
||||
}
|
||||
|
||||
public function addHeader($name, $type)
|
||||
{
|
||||
$this->headers->add($name, $type);
|
||||
}
|
||||
|
||||
public function addInput($name, $type)
|
||||
{
|
||||
$this->input->add($name, $type);
|
||||
}
|
||||
|
||||
public function setOutput($type)
|
||||
{
|
||||
$this->output->add('return', $type);
|
||||
}
|
||||
|
||||
public function getHeaders()
|
||||
{
|
||||
return $this->headers;
|
||||
}
|
||||
|
||||
public function getHeader($name, $default = null)
|
||||
{
|
||||
return $this->headers->get($name, $default);
|
||||
}
|
||||
|
||||
public function getInput()
|
||||
{
|
||||
return $this->input;
|
||||
}
|
||||
|
||||
public function getOutput()
|
||||
{
|
||||
return $this->output;
|
||||
}
|
||||
|
||||
public function getFault()
|
||||
{
|
||||
return $this->fault;
|
||||
}
|
||||
}
|
55
src/BeSimple/SoapCommon/Definition/Part.php
Normal file
55
src/BeSimple/SoapCommon/Definition/Part.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the BeSimpleSoap.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
* (c) Francis Besset <francis.besset@gmail.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace BeSimple\SoapCommon\Definition;
|
||||
|
||||
/**
|
||||
* @author Francis Besset <francis.besset@gmail.com>
|
||||
*/
|
||||
class Part
|
||||
{
|
||||
protected $name;
|
||||
protected $type;
|
||||
protected $nillable;
|
||||
|
||||
public function __construct($name, $type, $nillable = false)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->type = $type;
|
||||
$this->setNillable($nillable);
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function setType($type)
|
||||
{
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
public function isNillable()
|
||||
{
|
||||
return $this->nillable;
|
||||
}
|
||||
|
||||
public function setNillable($nillable)
|
||||
{
|
||||
$this->nillable = (boolean) $nillable;
|
||||
}
|
||||
}
|
30
src/BeSimple/SoapCommon/Definition/Type/ArrayOfType.php
Normal file
30
src/BeSimple/SoapCommon/Definition/Type/ArrayOfType.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the BeSimpleSoap.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
* (c) Francis Besset <francis.besset@gmail.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace BeSimple\SoapCommon\Definition\Type;
|
||||
|
||||
/**
|
||||
* @author Francis Besset <francis.besset@gmail.com>
|
||||
*/
|
||||
class ArrayOfType extends ComplexType
|
||||
{
|
||||
public function __construct($phpType, $arrayOf, $xmlTypeOf)
|
||||
{
|
||||
if ($arrayOf instanceof TypeInterface) {
|
||||
$arrayOf = $arrayOf->getPhpType();
|
||||
}
|
||||
|
||||
parent::__construct($phpType, 'ArrayOf'.ucfirst($xmlTypeOf ?: $arrayOf));
|
||||
|
||||
$this->add('item', $arrayOf);
|
||||
}
|
||||
}
|
39
src/BeSimple/SoapCommon/Definition/Type/ComplexType.php
Normal file
39
src/BeSimple/SoapCommon/Definition/Type/ComplexType.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the BeSimpleSoap.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
* (c) Francis Besset <francis.besset@gmail.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace BeSimple\SoapCommon\Definition\Type;
|
||||
|
||||
use BeSimple\SoapCommon\Definition\Message;
|
||||
|
||||
/**
|
||||
* @author Francis Besset <francis.besset@gmail.com>
|
||||
*/
|
||||
class ComplexType extends Message implements TypeInterface
|
||||
{
|
||||
public function __construct($phpType, $xmlType)
|
||||
{
|
||||
parent::__construct($xmlType);
|
||||
|
||||
$this->phpType = $phpType;
|
||||
$this->xmlType = $xmlType;
|
||||
}
|
||||
|
||||
public function getPhpType()
|
||||
{
|
||||
return $this->phpType;
|
||||
}
|
||||
|
||||
public function getXmlType()
|
||||
{
|
||||
return $this->xmlType;
|
||||
}
|
||||
}
|
38
src/BeSimple/SoapCommon/Definition/Type/Type.php
Normal file
38
src/BeSimple/SoapCommon/Definition/Type/Type.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the BeSimpleSoap.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
* (c) Francis Besset <francis.besset@gmail.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace BeSimple\SoapCommon\Definition\Type;
|
||||
|
||||
/**
|
||||
* @author Francis Besset <francis.besset@gmail.com>
|
||||
*/
|
||||
class Type implements TypeInterface
|
||||
{
|
||||
protected $phpType;
|
||||
protected $xmlType;
|
||||
|
||||
public function __construct($phpType, $xmlType)
|
||||
{
|
||||
$this->phpType = $phpType;
|
||||
$this->xmlType = $xmlType;
|
||||
}
|
||||
|
||||
public function getPhpType()
|
||||
{
|
||||
return $this->phpType;
|
||||
}
|
||||
|
||||
public function getXmlType()
|
||||
{
|
||||
return $this->xmlType;
|
||||
}
|
||||
}
|
23
src/BeSimple/SoapCommon/Definition/Type/TypeInterface.php
Normal file
23
src/BeSimple/SoapCommon/Definition/Type/TypeInterface.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the BeSimpleSoap.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
* (c) Francis Besset <francis.besset@gmail.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace BeSimple\SoapCommon\Definition\Type;
|
||||
|
||||
/**
|
||||
* @author Francis Besset <francis.besset@gmail.com>
|
||||
*/
|
||||
interface TypeInterface
|
||||
{
|
||||
public function getPhpType();
|
||||
|
||||
public function getXmlType();
|
||||
}
|
135
src/BeSimple/SoapCommon/Definition/Type/TypeRepository.php
Normal file
135
src/BeSimple/SoapCommon/Definition/Type/TypeRepository.php
Normal file
@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the BeSimpleSoap.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
* (c) Francis Besset <francis.besset@gmail.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace BeSimple\SoapCommon\Definition\Type;
|
||||
|
||||
use BeSimple\SoapCommon\Classmap;
|
||||
|
||||
/**
|
||||
* @author Christian Kerl <christian-kerl@web.de>
|
||||
* @author Francis Besset <francis.besset@gmail.com>
|
||||
*/
|
||||
class TypeRepository
|
||||
{
|
||||
const ARRAY_SUFFIX = '[]';
|
||||
|
||||
protected $xmlNamespaces = array();
|
||||
protected $types = array();
|
||||
|
||||
protected $classmap;
|
||||
|
||||
public function __construct(Classmap $classmap = null)
|
||||
{
|
||||
$this->classmap = $classmap;
|
||||
}
|
||||
|
||||
public function getXmlNamespaces()
|
||||
{
|
||||
return $this->xmlNamespaces;
|
||||
}
|
||||
public function getXmlNamespace($prefix)
|
||||
{
|
||||
return $this->xmlNamespaces[$prefix];
|
||||
}
|
||||
|
||||
public function addXmlNamespace($prefix, $url)
|
||||
{
|
||||
$this->xmlNamespaces[$prefix] = $url;
|
||||
}
|
||||
|
||||
public function getComplexTypes()
|
||||
{
|
||||
$types = array();
|
||||
foreach ($this->types as $type) {
|
||||
if ($type instanceof ComplexType) {
|
||||
$types[] = $type;
|
||||
}
|
||||
}
|
||||
|
||||
return $types;
|
||||
}
|
||||
|
||||
public function getType($phpType)
|
||||
{
|
||||
if (!$this->hasType($phpType)) {
|
||||
throw new \Exception();
|
||||
}
|
||||
|
||||
return $this->types[$phpType];
|
||||
}
|
||||
|
||||
public function addType($phpType, $xmlType)
|
||||
{
|
||||
return $this->types[$phpType] = $xmlType;
|
||||
}
|
||||
|
||||
public function addComplexType(ComplexType $type)
|
||||
{
|
||||
$phpType = $type->getPhpType();
|
||||
|
||||
$this->types[$phpType] = $type;
|
||||
$this->addClassmap($type->getXmlType(), $phpType);
|
||||
}
|
||||
|
||||
public function hasType($type)
|
||||
{
|
||||
if ($type instanceof TypeInterface) {
|
||||
$phpType = $type->getPhpType();
|
||||
|
||||
return !(!$this->hasType($phpType) || $type !== $this->getType($phpType));
|
||||
}
|
||||
|
||||
if (isset($this->types[$type])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (false !== $arrayOf = $this->getArrayOf($type)) {
|
||||
if ($this->hasType($arrayOf)) {
|
||||
$xmlTypeOf = null;
|
||||
$arrayOfType = $this->getType($arrayOf);
|
||||
if ($arrayOfType instanceof ComplexType) {
|
||||
$xmlTypeOf = $arrayOfType->getXmlType();
|
||||
}
|
||||
|
||||
$arrayType = new ArrayOfType($type, $arrayOf, $xmlTypeOf);
|
||||
$this->addType($type, $arrayType);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getArrayOf($arrayType)
|
||||
{
|
||||
if (!preg_match('#(.*)'.preg_quote(static::ARRAY_SUFFIX, '#').'$#', $arrayType, $match)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $match[1];
|
||||
}
|
||||
|
||||
public function getClassmap()
|
||||
{
|
||||
return $this->classmap;
|
||||
}
|
||||
|
||||
protected function addClassmap($xmlType, $phpType)
|
||||
{
|
||||
if (!$this->classmap) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->classmap->add($xmlType, $phpType);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user