Overview

Packages

  • application
    • commands
    • components
      • actions
      • filters
      • leftWidget
      • permissions
      • sortableWidget
      • util
      • webupdater
      • x2flow
        • actions
        • triggers
      • X2GridView
      • X2Settings
    • controllers
    • models
      • embedded
    • modules
      • accounts
        • controllers
        • models
      • actions
        • controllers
        • models
      • calendar
        • controllers
        • models
      • charts
        • models
      • contacts
        • controllers
        • models
      • docs
        • components
        • controllers
        • models
      • groups
        • controllers
        • models
      • marketing
        • components
        • controllers
        • models
      • media
        • controllers
        • models
      • mobile
        • components
      • opportunities
        • controllers
        • models
      • products
        • controllers
        • models
      • quotes
        • controllers
        • models
      • services
        • controllers
        • models
      • template
        • models
      • users
        • controllers
        • models
      • workflow
        • controllers
        • models
      • x2Leads
        • controllers
        • models
  • Net
  • None
  • PHP
  • system
    • base
    • caching
      • dependencies
    • collections
    • console
    • db
      • ar
      • schema
        • cubrid
        • mssql
        • mysql
        • oci
        • pgsql
        • sqlite
    • i18n
      • gettext
    • logging
    • test
    • utils
    • validators
    • web
      • actions
      • auth
      • filters
      • form
      • helpers
      • renderers
      • services
      • widgets
        • captcha
        • pagers
  • Text
    • Highlighter
  • zii
    • behaviors
    • widgets
      • grid
      • jui

Classes

  • CDocumentSoapObjectWrapper
  • CSoapObjectWrapper
  • CWebService
  • CWebServiceAction
  • CWsdlGenerator
  • Overview
  • Package
  • Class
  • Tree

Class CWsdlGenerator

CWsdlGenerator generates the WSDL for a given service class.

The WSDL generation is based on the doc comments found in the service class file. In particular, it recognizes the '@soap' tag in the comment and extracts API method and type definitions.

In a service class, a remote invokable method must be a public method with a doc comment block containing the '@soap' tag. In the doc comment, the type and name of every input parameter and the type of the return value should be declared using the standard phpdoc format.

CWsdlGenerator recognizes the following primitive types (case-sensitive) in the parameter and return type declarations:
  • str/string: maps to xsd:string;
  • int/integer: maps to xsd:int;
  • float/double: maps to xsd:float;
  • bool/boolean: maps to xsd:boolean;
  • date: maps to xsd:date;
  • time: maps to xsd:time;
  • datetime: maps to xsd:dateTime;
  • array: maps to xsd:string;
  • object: maps to xsd:struct;
  • mixed: maps to xsd:anyType.

If a type is not a primitive type, it is considered as a class type, and CWsdlGenerator will look for its property declarations. Only public properties are considered, and they each must be associated with a doc comment block containg the '@soap' tag. The doc comment block should declare the type of the property.

CWsdlGenerator recognizes the array type with the following format:

typeName[]: maps to tns:typeNameArray

The following is an example declaring a remote invokable method:

/ **
  * A foo method.
  * @param string name of something
  * @param string value of something
  * @return string[] some array
  * @soap
  * /
public function foo($name,$value) {...}

And the following is an example declaring a class with remote accessible properties:

class Foo {
    / **
      * @var string name of foo {nillable=1, minOccurs=0, maxOccurs=2}
      * @soap
      * /
    public $name;
    / **
      * @var Member[] members of foo
      * @soap
      * /
    public $members;
}

In the above, the 'members' property is an array of 'Member' objects. Since 'Member' is not a primitive type, CWsdlGenerator will look further to find the definition of 'Member'.

Optionally, extra attributes (nillable, minOccurs, maxOccurs) can be defined for each property by enclosing definitions into curly brackets and separated by comma like so:

{[attribute1 = value1][, attribute2 = value2], ...}

where the attribute can be one of following:
  • nillable = [0|1|true|false]
  • minOccurs = n; where n>=0
  • maxOccurs = n; where [n>=0|unbounded]
Additionally, each complex data type can have assigned a soap indicator flag declaring special usage for such a data type. A soap indicator must be declared in the doc comment block with the '@soap-indicator' tag. Following soap indicators are currently supported:
  • all - (default) allows any sorting order of child nodes
  • sequence - all child nodes in WSDL XML file will be expected in predefined order
  • choice - supplied can be either of the child elements
The Group indicators can be also injected via custom soap definitions as XML node into WSDL structure.

In the following example, class Foo will create a XML node <xsd:Foo><xsd:sequence> ... </xsd:sequence></xsd:Foo> with children attributes expected in pre-defined order.

/ *
  * @soap-indicator sequence
  * /
class Foo {
    ...
}

For more on soap indicators, see See http://www.w3schools.com/schema/schema_complex_indicators.asp.

Since the variability of WSDL definitions is virtually unlimited, a special doc comment tag '@soap-wsdl' can be used in order to inject any custom XML string into generated WSDL file. If such a block of the code is found in class's comment block, then it will be used instead of parsing and generating standard attributes within the class. This gives virtually unlimited flexibility in defining data structures of any complexity. Following is an example of defining custom piece of WSDL XML node:

/ *
  * @soap-wsdl <xsd:sequence>
  * @soap-wsdl  <xsd:element minOccurs="1" maxOccurs="1" nillable="false" name="name" type="xsd:string"/>
  * @soap-wsdl  <xsd:choice minOccurs="1" maxOccurs="1" nillable="false">
  * @soap-wsdl          <xsd:element minOccurs="1" maxOccurs="1" nillable="false" name="age" type="xsd:integer"/>
  * @soap-wsdl          <xsd:element minOccurs="1" maxOccurs="1" nillable="false" name="date_of_birth" type="xsd:date"/>
  * @soap-wsdl  </xsd:choice>
  * @soap-wsdl </xsd:sequence>
  * /
class User {
    / **
      * @var string User name {minOccurs=1, maxOccurs=1}
      * @soap
      * /
    public $name;
    / **
      * @var integer User age {nillable=0, minOccurs=1, maxOccurs=1}
      * @example 35
      * @soap
      * /
    public $age;
    / **
      * @var date User's birthday {nillable=0, minOccurs=1, maxOccurs=1}
      * @example 1980-05-27
      * @soap
      * /
    public $date_of_birth;
}

In the example above, WSDL generator would inject under XML node <xsd:User> the code block defined by @soap-wsdl lines.

By inserting into SOAP URL link the parameter "?makedoc", WSDL generator will output human-friendly overview of all complex data types rather than XML WSDL file. Each complex type is described in a separate HTML table and recognizes also the '@example' PHPDoc tag. See CWsdlGenerator::buildHtmlDocs().

CComponent
Extended by CWsdlGenerator
Package: system\web\services
Copyright: 2008-2013 Yii Software LLC
License: http://www.yiiframework.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 1.0
Located at x2engine/framework/web/services/CWsdlGenerator.php
Methods summary
public string
# generateWsdl( string $className, string $serviceUrl, string $encoding = 'UTF-8' )

Generates the WSDL for the given class.

Generates the WSDL for the given class.

Parameters

$className
string
$className class name
$serviceUrl
string
$serviceUrl Web service URL
$encoding
string
$encoding encoding of the WSDL. Defaults to 'UTF-8'.

Returns

string
the generated WSDL
protected
# processMethod( ReflectionMethod $method )

Parameters

$method
ReflectionMethod
$method method
protected
# processType( string $type )

Parameters

$type
string
$type PHP variable type
protected
# getWsdlElementAttributes( string $comment )

Parse attributes nillable, minOccurs, maxOccurs

Parse attributes nillable, minOccurs, maxOccurs

Parameters

$comment
string
$comment Extracted PHPDoc comment
protected
# injectDom( DOMDocument $dom, DOMElement $target, DOMNode $source )

Import custom XML source node into WSDL document under specified target node

Import custom XML source node into WSDL document under specified target node

Parameters

$dom
DOMDocument
$dom XML WSDL document being generated
$target
DOMElement
$target XML node, to which will be appended $source node
$source
DOMNode
$source Source XML node to be imported
protected
# buildDOM( string $serviceUrl, string $encoding )

Parameters

$serviceUrl
string
$serviceUrl Web service URL
$encoding
string
$encoding encoding of the WSDL. Defaults to 'UTF-8'.
protected
# addTypes( DOMDocument $dom )

Parameters

$dom
DOMDocument
$dom Represents an entire HTML or XML document; serves as the root of the document tree
protected
# addMessages( DOMDocument $dom )

Parameters

$dom
DOMDocument
$dom Represents an entire HTML or XML document; serves as the root of the document tree
protected
# addPortTypes( DOMDocument $dom )

Parameters

$dom
DOMDocument
$dom Represents an entire HTML or XML document; serves as the root of the document tree
protected
# createPortElement( DOMDocument $dom, string $name, string $doc )

Parameters

$dom
DOMDocument
$dom Represents an entire HTML or XML document; serves as the root of the document tree
$name
string
$name method name
$doc
string
$doc doc
protected
# addBindings( DOMDocument $dom )

Parameters

$dom
DOMDocument
$dom Represents an entire HTML or XML document; serves as the root of the document tree
protected
# createOperationElement( DOMDocument $dom, string $name, array $headers = null )

Parameters

$dom
DOMDocument
$dom Represents an entire HTML or XML document; serves as the root of the document tree
$name
string
$name method name
$headers
array
$headers array like array('input'=>array(MESSAGE,PART),'output=>array(MESSAGE,PART))
protected
# addService( DOMDocument $dom, string $serviceUrl )

Parameters

$dom
DOMDocument
$dom Represents an entire HTML or XML document; serves as the root of the document tree
$serviceUrl
string
$serviceUrl Web service URL
public
# buildHtmlDocs( boolean $return = false )

Generate human friendly HTML documentation for complex data types. This method can be invoked either by inserting URL parameter "&makedoc" into URL link, e.g. "http://www.mydomain.com/soap/create?makedoc", or simply by calling from another script with argument $return=true.

Generate human friendly HTML documentation for complex data types. This method can be invoked either by inserting URL parameter "&makedoc" into URL link, e.g. "http://www.mydomain.com/soap/create?makedoc", or simply by calling from another script with argument $return=true.

Each complex data type is described in a separate HTML table containing following columns:
  • # - attribute ID
  • Attribute - attribute name, e.g. firstname
  • Type - attribute type, e.g. integer, date, tns:SoapPovCalculationResultArray
  • Nill - true|false - whether the attribute is nillable
  • Min - minimum number of occurrences
  • Max - maximum number of occurrences
  • Description - Detailed description of the attribute.
  • Example - Attribute example value if provided via PHPDoc property @example.

Parameters

$return
boolean
$return If true, generated HTML output will be returned rather than directly sent to output buffer
Methods inherited from CComponent
__call(), __get(), __isset(), __set(), __unset(), asa(), attachBehavior(), attachBehaviors(), attachEventHandler(), canGetProperty(), canSetProperty(), detachBehavior(), detachBehaviors(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), getEventHandlers(), hasEvent(), hasEventHandler(), hasProperty(), raiseEvent()
Constants summary
string STYLE_RPC 'rpc'
#
string STYLE_DOCUMENT 'document'
#
string USE_ENCODED 'encoded'
#
string USE_LITERAL 'literal'
#
Properties summary
public string $namespace
#

the namespace to be used in the generated WSDL. If not set, it defaults to the name of the class that WSDL is generated upon.

the namespace to be used in the generated WSDL. If not set, it defaults to the name of the class that WSDL is generated upon.

public string $serviceName
#

the name of the generated WSDL. If not set, it defaults to "urn:{$className}wsdl".

the name of the generated WSDL. If not set, it defaults to "urn:{$className}wsdl".

public array $operationBodyStyle array( 'use' => self::USE_ENCODED, 'encodingStyle' => 'http://schemas.xmlsoap.org/soap/encoding/', )
#

soap:body operation style options

soap:body operation style options

public array $bindingStyle CWsdlGenerator::STYLE_RPC
#

soap:operation style

soap:operation style

public string $bindingTransport 'http://schemas.xmlsoap.org/soap/http'
#

soap:operation transport

soap:operation transport

protected static array $typeMap array( 'string'=>'xsd:string', 'str'=>'xsd:string', 'int'=>'xsd:int', 'integer'=>'xsd:integer', 'float'=>'xsd:float', 'double'=>'xsd:float', 'bool'=>'xsd:boolean', 'boolean'=>'xsd:boolean', 'date'=>'xsd:date', 'time'=>'xsd:time', 'datetime'=>'xsd:dateTime', 'array'=>'soap-enc:Array', 'object'=>'xsd:struct', 'mixed'=>'xsd:anyType', )
#
protected array $operations
#

List of recognized SOAP operations that will become remotely available. All methods with declared @soap parameter will be included here in the format operation1 => description1, operation2 => description2, ..

List of recognized SOAP operations that will become remotely available. All methods with declared @soap parameter will be included here in the format operation1 => description1, operation2 => description2, ..

protected array $types
#

List of complex types used by operations. If an SOAP operation defines complex input or output type, all objects are included here containing all sub-parameters. For instance, if an SOAP operation "createUser" requires complex input object "User", then the object "User" will be included here with declared subparameters such as "firstname", "lastname", etc..

List of complex types used by operations. If an SOAP operation defines complex input or output type, all objects are included here containing all sub-parameters. For instance, if an SOAP operation "createUser" requires complex input object "User", then the object "User" will be included here with declared subparameters such as "firstname", "lastname", etc..

protected array $elements
#
protected array $messages
#

Map of request and response types for all operations.

Map of request and response types for all operations.

API documentation generated by ApiGen 2.8.0