Giter Site home page Giter Site logo

wsdl-creator's Introduction

PHP WSDL Creator

Build Status Scrutinizer Quality Score Coverage Status Dependency Status

Introduction

WSDL creator allows generating WSDL documents based on PHP classes using annotations and reflection mechanism. This generator also give possibilty to generating overview methods and parameters with SOAP examples used in WSDL.

Support: >= PHP5.5.

Installation

To install wsdl-creator at your project use composer.

###Create new project:

composer.phar create-project georgo/wsdl-creator myproject

###or add to the composer.json file:

require: {
	"georgo/wsdl-creator": "1.*"
}

Configuration

To start working with creator you must create new WSDLCreator object and define for him:

  • class to generate WSDL
  • SOAP server location
  • documnet namespace.
$wsdl = new WSDL\WSDLCreator('ClassName', 'http://localhost/wsdl-creator/ClassName.php');
$wsdl->setNamespace("http://foo.bar/");

SOAP server must be created in location specified in WSDLCreator.

$server = new SoapServer(null, array(
    'uri' => 'http://localhost/wsdl-creator/ClassName.php'
));
$server->setClass('ClassName');
$server->handle();

To render XML use method renderWSDL. To properly load generator classes use composer loader which is in vendor/autoload.php.

Full configutaion listing:

require_once 'vendor/autoload.php';

use WSDL\WSDLCreator;

if (isset($_GET['wsdl'])) {
    $wsdl = new WSDL\WSDLCreator('ClassName', 'http://localhost/wsdl-creator/ClassName.php');
    $wsdl->setNamespace("http://foo.bar/");
    $wsdl->renderWSDL();
    exit;
}

$server = new SoapServer(null, array(
    'uri' => 'http://localhost/wsdl-creator/ClassName.php'
));
$server->setClass('ClassName');
$server->handle();

Now if we try call address http://localhost/wsdl-creator/ClassName.php?wsdl you recive WSDL document.

Define web service method

To define is a web service method you must use @WebMethod annotation.

Simple type

Simple types are described here.

###Usage

/**
* @param string $name
*/

So you type @param next type one of simple types (string) after name of variable ($name).


You can also use arrays of the simple types.

###Usage

/**
* @param string[] $names
*/

In input parameter now you must define what type of array you pass (string[]).


###Example

SimpleTypeExample


###Annotations

  • @desc Method description
  • @param type $varialbe_name
  • @return type $return

Wrapper type

Wrapper types are user defined clases which you can generate WSDL complex types.

###Usage

/**
* @param wrapper $user @className=User
*/

You must define class User with public fields and doc comments which contains field type as example:

class User
{
	/**
	* @type string
	*/
	public $name;
	/**
	* @type int
	*/
	public $age;
}

This mechanism use reflection, i.e. User class must be visible to the generated class - possible use namespaces (\Namespace\To\User).


You can define arrays of wrappers.

###Usage

/**
* @return wrapper[] $users @className=User
*/

This annotation will generate array of users.


###Example

WrapperTypeExample


###Annotations

  • @desc Method description
  • @param wrapper[] @className=ClassName
  • @return wrapper @className=\Namespace\To\ClassName

Object type

You can dynamically create object at runtime. Use object parameter type.

###Usage

/**
* @param object $info @string=$name @int=$age
*/

This annotation create complex type with name and age elements.


Also you can wrapp classes in object.

###Usage

/**
* @return object $userNameWithId @(wrapper $user @className=User) @int=$id
*/

Above example will return UserNameWithId object which contains pointer to User complex type and int type.


Another option is creating array of objects.

###Usage

/**
* @param object[] $payments @float=$payment @string=$user
*/

This annotation creata array of objects with payment and user on each element of array.


###Example

ObjectTypeExample


###Additional info

In object you can use array of wrappers and array of simple types.


###Annotations

  • @desc Method description
  • @param object $object @type1=$name1 @type2=$name2
  • @param object $object @(wrapper $nameWrapper @className=User) @type1=$name1
  • @param object[] $object @type1[]=$name1
  • @return

Service overview

You can generate service overview through renderWSDLService method. This show all infos about method and parameters used in service with sample SOAP request.

###Example

Wrapper image

Styles

By default, the WSDLCreator will generate WSDLs using the rpc/literal binding style.

To specify rpc/encoded or a wrapped document/literal binding style, set the binding style on the WSDLCreator object.

$wsdl = new WSDL\WSDLCreator('ClassName', 'http://localhost/wsdl-creator/ClassName.php');
@wsdl->setBindingStyle(new WSDL\XML\Styles\RpcEncoded());
$wsdl->setNamespace("http://foo.bar/");

When specifying the wrapped document/literal binding style, you can use WSDL\DocumentLiteralWrapper to automatically wrap the returning value in an appropriate wrapped object.

require_once 'vendor/autoload.php';

use WSDL\DocumentLiteralWrapper;
use WSDL\WSDLCreator;
use WSDL\XML\Styles\DocumentLiteralWrapped;

if (isset($_GET['wsdl'])) {
    $wsdl = new WSDLCreator('ClassName', 'http://localhost/wsdl-creator/ClassName.php');
    @wsdl->setBindingStyle(new DocumentLiteralWrapped());
    $wsdl->setNamespace("http://foo.bar/");
    $wsdl->renderWSDL();
    exit;
}

ini_set('soap.wsdl_cache_enabled', '0');
$server = new SoapServer('http://localhost/wsdl-creator/ClassName.php?wsdl', array(
	'style' => SOAP_DOCUMENT,
	'use' => SOAP_LITERAL,
));
$server->setObject(new DocumentLiteralWrapped(new ClassName()));
$server->handle();

wsdl-creator's People

Contributors

anotherlatenightcoder avatar georgo avatar piotrooo avatar rhelms avatar riso348 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.