public function output($doc = true, $wsdl = false, $phpclient = false)
 {
     require_once PROJECT_PATH . '/lib/php-wsdl-2.3/class.phpwsdl.php';
     $soap = \PhpWsdl::CreateInstance('API', null, null, array(PROJECT_PATH . '/lib/soapapi/v1/soapapihandler.class.php'), null, null, null, false, false);
     // Don't start the SOAP server right now
     // Disable caching for demonstration
     ini_set('soap.wsdl_cache_enabled', 0);
     // Disable caching in PHP
     \PhpWsdl::$CacheTime = 0;
     // Disable caching in PhpWsdl
     if ($wsdl) {
         $soap->ForceOutputWsdl = true;
     } else {
         if ($phpclient) {
             $soap->ForceOutputPhp = true;
         } else {
             $this->ForceOutputHtml = true;
         }
     }
     //$soap->Optimize = false;
     $soap->RunServer();
 }
示例#2
0
// need a special handling.
// To get rid of the NULL problem you need to ensure that the PHP
// SoapServer has no knowledge of the WSDL. To ensure this, set the
// PhpWsdl::$UseProxyWsdl property to FALSE (is FALSE per default).
//
// If you want to mix class and global methods, you need to use the proxy.
// Include the demonstration classes
require_once 'class.soapdemo.php';
require_once 'class.complextypedemo.php';
// Initialize the PhpWsdl class
require_once 'class.phpwsdl.php';
PhpWsdlMethod::$DefaultException = 'SoapFault';
// This will set SoapFault as exception type for all methods
PhpWsdl::$UseProxyWsdl = true;
// Comment this line out to get rid of "Missing parameter" exceptions and to use the method "AnotherDemoMethod" exported by the class "SecondClass"
$soap = PhpWsdl::CreateInstance(null, null, './cache', array('class.soapdemo.php', 'class.complextypedemo.php', __FILE__), null, null, null, false, false);
// Don't start the SOAP server right now
// Disable caching for demonstration
ini_set('soap.wsdl_cache_enabled', 0);
// Disable caching in PHP
PhpWsdl::$CacheTime = 0;
// Disable caching in PhpWsdl
// Run the SOAP server
if ($soap->IsWsdlRequested()) {
    $soap->Optimize = false;
}
// Don't optimize WSDL to send it human readable to the browser
$soap->RunServer(null, array('SoapDemo', new SoapDemo()));
/**
 * This is how to define a global method for WSDL
 * 
 /**
  * Create/Fill a PhpWsdl object from WSDL
  * 
  * @param PhpWsdl An existing PhpWsdl object (default: NULL)
  * @return PhpWsdl The PhpWsdl object
  */
 public function CreateServerFromWsdl($soap = null)
 {
     PhpWsdl::Debug('Create/Fill a PhpWsdl object from WSDL');
     if (is_null($soap)) {
         if (!is_null($this->Server)) {
             PhpWsdl::Debug('Return existing object');
             return $this->Server;
         }
         $soap = PhpWsdl::CreateInstance();
     } else {
         PhpWsdl::Debug('Use existing object');
     }
     if (!is_null($soap->GetWsdlFromCache())) {
         PhpWsdl::Debug('Server created from cached values');
         if (is_null($this->Server)) {
             $this->Server = $soap;
         }
         return $soap;
     }
     // Configuration
     $soap->WsdlUri = $this->WsdlUri;
     $this->ParseWsdl();
     if (!is_null($this->ServiceName)) {
         $soap->Name = $this->ServiceName;
     }
     if (!is_null($this->NameSpace)) {
         $soap->NameSpace = $this->NameSpace;
     }
     $client = $this->GetClient();
     // Methods
     $fnc = $client->__getFunctions();
     $i = -1;
     $len = sizeof($fnc);
     while (++$i < $len) {
         $f = $fnc[$i];
         list($type, $method, $temp) = explode("\t", preg_replace(self::$methodRx, "\$1\t\$2\t\$3", $f));
         PhpWsdl::Debug('Found method #' . $i . ' ' . $method);
         if (!is_null($soap->GetMethod($method))) {
             $this->Warn('WARNING: Double method detected!');
             continue;
         }
         $m = new PhpWsdlMethod($method);
         $temp = explode(' ', $temp);
         $pLen = sizeof($temp);
         for ($j = 0; $j < $pLen - 1; $j++) {
             list($t, $n) = array($temp[$j], $temp[$j + 1]);
             PhpWsdl::Debug('Found parameter #' . $j . ' ' . $n . ' type of ' . $t);
             $m->Param[] = new PhpWsdlParam(substr($n, 1), $t);
         }
         if ($type != 'void') {
             $m->Return = new PhpWsdlParam('return', $type);
         }
         $soap->Methods[] = $m;
     }
     // Types
     $typ = $client->__getTypes();
     $i = -1;
     $len = sizeof($typ);
     while (++$i < $len) {
         $t = $typ[$i];
         list($type, $name) = explode("\t", preg_replace(self::$typeRx, "\$1\t\$2", $t));
         PhpWsdl::Debug('Found type #' . $i . ' ' . $name . ' type of ' . $type);
         if (!is_null($soap->GetType($name))) {
             $this->Warn('WARNING: Double type detected!');
             continue;
         }
         $arr = strpos($t, '[]') > -1;
         if ($arr) {
             PhpWsdl::Debug('Array type');
             $y = new PhpWsdlComplex($name);
             $y->Type = $type;
             $y->IsArray = true;
             $soap->Types[] = $y;
         } else {
             if ($type == 'struct') {
                 PhpWsdl::Debug('Complex type');
                 $el = array();
                 $temp = explode("\n", $t);
                 $j = 0;
                 $eLen = sizeof($temp) - 1;
                 while (++$j < $eLen) {
                     list($p, $n) = explode("\t", preg_replace(self::$elementRx, "\$1\t\$2", $temp[$j]), 2);
                     PhpWsdl::Debug('Found element #' . $j . ' ' . $n . ' type of ' . $p);
                     $el[] = new PhpWsdlElement($n, $p);
                 }
                 $y = new PhpWsdlComplex($name, $el);
                 $y->IsArray = false;
                 $soap->Types[] = $y;
             } else {
                 $this->Warn('WARNING: Could not create type ' . $t);
             }
         }
     }
     if (is_null($this->Server)) {
         $this->Server = $soap;
     }
     return $soap;
 }
 /**
  * Fill an PhpWsdl object with data from an NuSOAP object
  * Development status: Beta
  * 
  * @param nusoap_server $nusoap NuSOAP server object
  * @param PhpWsdl $phpwsdl PhpWsdl object or NULL to create a new one (default: NULL)
  * @return PhpWsdl PhpWsdl object
  */
 public static function CreatePhpWsdl($nusoap, $phpwsdl = null)
 {
     //TODO This has still to be tested with some real NuSOAP webservice objects!
     PhpWsdl::Debug('Create PhpWsdl from NuSOAP');
     if (is_null($phpwsdl)) {
         $phpwsdl = PhpWsdl::CreateInstance();
     }
     // Basic configuration
     $phpwsdl->Name = $nusoap->wsdl->serviceName;
     $phpwsdl->EndPoint = $nusoap->wsdl->endpoint;
     $phpwsdl->NameSpace = $nusoap->wsdl->namespaces['tns'];
     // Types
     PhpWsdl::Debug('Add types');
     $ntl = $nusoap->wsdl->schemas[$phpwsdl->NameSpace][0]->complexTypes;
     $keys = array_keys($ntl);
     $i = -1;
     $len = sizeof($keys);
     while (++$i < $len) {
         $nt = $ntl[$keys[$i]];
         $name = $nt['name'];
         PhpWsdl::Debug('Add type ' . $name);
         if (!is_null($phpwsdl->GetType($name))) {
             PhpWsdl::Debug('WARNING: Double type detected!');
             continue;
         }
         if ($nt['typeClass'] == 'complexType' && $nt['phpType'] == 'array') {
             // Array
             PhpWsdl::Debug('Array type');
             list($temp, $type) = explode(':', $nt['arrayType'], 2);
             $t = new PhpWsdlComplex($name);
             $t->Type = $type;
             $t->IsArray = true;
             $phpwsdl->Types[] = $t;
         } else {
             if ($nt['typeClass'] == 'complexType') {
                 // Complex type
                 PhpWsdl::Debug('Complex type');
                 if ($nt['phpType'] != 'struct') {
                     PhpWsdl::Debug('WARNING: Not a PHP struct');
                 }
                 if ($nt['compositor'] != 'sequence') {
                     PhpWsdl::Debug('WARNING: Not sequenced elements');
                 }
                 $el = array();
                 $ek = array_keys($nt['elements']);
                 $j = -1;
                 $eLen = sizeof($ek);
                 while (++$j < $eLen) {
                     $n = $nt['elements'][$ek[$j]]['name'];
                     list($temp, $type) = explode(':', $nt['elements'][$ek[$j]]['type']);
                     PhpWsdl::Debug('Found element ' . $n . ' type of ' . $type);
                     $el[] = new PhpWsdlElement($n, $type);
                 }
                 $phpwsdl->Types[] = new PhpWsdlComplex($name, $el);
             } else {
                 if ($nt['typeClass'] == 'simpleType') {
                     // Enumeration
                     PhpWsdl::Debug('Enumeration');
                     list($temp, $type) = explode(':', $nt['type']);
                     $phpwsdl->Types[] = new PhpWsdlEnum($name, $type, $nt['enumeration']);
                 } else {
                     PhpWsdl::Debug('WARNING: PHP type "' . $nt['phpType'] . '" is not supported!');
                 }
             }
         }
     }
     // Methods
     PhpWsdl::Debug('Add methods');
     $nml = $nusoap->operations;
     $keys = array_keys($nml);
     $i = -1;
     $len = sizeof($keys);
     while (++$i < $len) {
         $nm = $nml[$keys[$i]];
         // Get the method name
         $name = $nml['name'];
         PhpWsdl::Debug('Add method ' . $name);
         $glob = strpos($name, '.') < 0;
         if (!$glob) {
             list($temp, $name) = explode('.', $name, 2);
             PhpWsdl::Debug('Class method ' . $name);
         } else {
             PhpWsdl::Debug('Global method');
         }
         if (!is_null($phpwsdl->GetMethod($name))) {
             PhpWsdl::Debug('WARNING: Double method detected!');
             continue;
         }
         // Get parameters
         $param = array();
         $pk = array_keys($nm['in']);
         $j = -1;
         $pLen = sizeof($pk);
         while (++$j < $pLen) {
             list($temp, $type) = explode(':', $nm['in'][$pk[$j]], 2);
             PhpWsdl::Debug('Parameter ' . $ok[$j] . ' type of ' . $type);
             $param[] = new PhpWsdlParam($pk[$j], $type);
         }
         // Get return type
         $r = null;
         if (sizeof($nm['out']) > 0) {
             $pk = array_keys($nm['in']);
             list($temp, $type) = explode(':', $nm['out'][$pk[0]], 2);
             PhpWsdl::Debug('Return ' . $pk[0] . ' type of ' . $type);
             $r = new PhpWsdlParam($pk[0], $type);
         }
         // Create method
         $m = new PhpWsdlMethod($name, $param, $r);
         $m->IsGlobal = $glob;
         $phpwsdl->Methods[] = $m;
     }
     return $phpwsdl;
 }
示例#5
0
<?php

// This is a demonstration how to work with PhpWsdl without WSDL definitions in comments.
// More code, less comments. For whoever needs it... You may also mix definitions in
// comments AND in this way together.
// Include the demonstration classes
require_once 'class.soapdemo.php';
require_once 'class.complextypedemo.php';
// Initialize the PhpWsdl class
require_once 'class.phpwsdl.php';
PhpWsdlMethod::$DefaultException = 'SoapFault';
// This will set SoapFault as exception type for all methods
$soap = PhpWsdl::CreateInstance(null, null, './cache', null, 'SoapDemo', array(new PhpWsdlMethod('GetComplexType', null, new PhpWsdlParam('GetComplexTypeResult', 'ComplexTypeDemoB')), new PhpWsdlMethod('PrintComplexType', array(new PhpWsdlParam('obj', 'ComplexTypeDemoB')), new PhpWsdlParam('PrintComplexTypeResult', 'string')), new PhpWsdlMethod('ComplexTypeArrayDemo', array(new PhpWsdlParam('arr', 'ComplexTypeDemoBArray')), new PhpWsdlParam('return', 'stringArray')), new PhpWsdlMethod('SayHello', array(new PhpWsdlParam('name', 'string')), new PhpWsdlParam('return', 'string')), new PhpWsdlMethod('DemoMethod')), array(new PhpWsdlComplex('ComplexTypeDemo', array(new PhpWsdlElement('StringA', 'string'), new PhpWsdlElement('StringB', 'string'), new PhpWsdlElement('Integer', 'int'), new PhpWsdlElement('Boolean', 'boolean'))), new PhpWsdlComplex('ComplexTypeDemoB', array(new PhpWsdlElement('AdditionalString', 'string')), array('inherit' => 'ComplexTypeDemo')), new PhpWsdlComplex('stringArray'), new PhpWsdlComplex('ComplexTypeDemoArray'), new PhpWsdlEnum('DemoEnum', 'string', array('ValueA', 'ValueB', 'ValueC')), new PhpWsdlComplex('SoapFault', array(new PhpWsdlElement('message', 'string'), new PhpWsdlElement('code', 'int'), new PhpWsdlElement('file', 'string'), new PhpWsdlElement('line', 'int')))), false, false);
// Don't start the SOAP server right now
// Disable caching for demonstration
ini_set('soap.wsdl_cache_enabled', 0);
// Disable caching in PHP
PhpWsdl::$CacheTime = 0;
// Disable caching in PhpWsdl
// Run the SOAP server
if ($soap->IsWsdlRequested()) {
    $soap->Optimize = false;
}
// Don't optimize WSDL to send it human readable to the browser
$soap->RunServer();
// Finally, run the server
示例#6
0
<?php

// This demonstrates how to mix up global methods and methods from multiple
// handler classes without using the PhpWsdlProxy class.
require_once 'class.phpwsdl.php';
/*PhpWsdl::$Debugging=true;
PhpWsdl::$DebugFile='./cache/debug.log';*/
PhpWsdlMethod::$DefaultException = 'SoapFault';
// This will set SoapFault as exception type for all methods
ini_set('soap.wsdl_cache_enabled', 0);
// Disable caching in PHP
PhpWsdl::$CacheTime = 0;
// Disable caching in PhpWsdl
$soap->CreateHandler = true;
// Enable creating a PhpWsdlHandler class at runtime (this does the trick, finally)
$soap = PhpWsdl::CreateInstance();
$soap->Files = array('class.soapdemo.php', 'class.complextypedemo.php', __FILE__);
$soap->RunServer();
/**
 * This is how to define a global method for WSDL.
 * 
 * @return string Response
 * @pw_set global=1 -> Tell PhpWsdl to serve this as global method (outside of a class)
 */
function GlobalMethodDemo()
{
    return utf8_encode('Response of the global method demo');
}
class SecondClass
{
    /**
示例#7
0
<?php

// This demonstrates the usage of the Zend adapter. It requires the
// PhpWsdl framework files to be in the same folder as this file.
// Load PhpWsdl
require_once 'class.phpwsdl.php';
// Load the Zend extension, if PhpWsdl could not do it
// (because the "glob" function may be disabled in your PHP installation)
// If "glob" is working, you don't need the following two lines:
if (!class_exists('PhpWsdlZend')) {
    require_once 'class.phpwsdl.zend.php';
}
// Run the SOAP server in quick mode
PhpWsdl::CreateInstance(true, array('class.soapdemo.php', 'class.complextypedemo.php'));
示例#8
0
<?php

/**
 * Created by PhpStorm.
 * User: vignatyev
 * Date: 23.11.2015
 * Time: 9:44
 */
require_once 'Session.php';
require_once 'php-wsdl/class.phpwsdl.php';
$soap = PhpWsdl::CreateInstance(null, null, './cache', array('Session.php'), null, null, null, false, false);
// Don't start the SOAP server right now
// Disable caching for demonstration
ini_set('soap.wsdl_cache_enabled', 0);
// Disable caching in PHP
PhpWsdl::$CacheTime = 0;
// Disable caching in PhpWsdl
// Run the SOAP server
if ($soap->IsWsdlRequested()) {
    // WSDL requested by the client?
    $soap->Optimize = false;
}
// Don't optimize WSDL to send it human readable to the browser
//$soap->ParseDocs=false;				// Uncomment this line to disable the whole documentation features
//$soap->IncludeDocs=false;				// Uncomment this line to disable writing the documentation in WSDL XML
//$wsdl=$soap->CreateWsdl();			// This would save the WSDL XML string in $wsdl
//$php=$soap->OutputPhp(false,false);	// This would save a PHP SOAP client as PHP source code string in $php
//$html=$soap->OutputHtml(false,false);	// This would save the HTML documentation string in $html
$soap->RunServer();
示例#9
0
<?php

// This is a demonstration how to work with PhpWsdl without WSDL definitions in comments.
// More code, less comments. For whoever needs it... You may also mix definitions in
// comments AND in this way together.
// Include the demonstration classes
require_once 'class.soapdemo.php';
require_once 'class.complextypedemo.php';
// Initialize the PhpWsdl class
require_once 'class.phpwsdl.php';
$soap = PhpWsdl::CreateInstance(null, null, './cache', null, 'SoapDemo', array(new PhpWsdlMethod('GetComplexType', null, new PhpWsdlParam('GetComplexTypeResult', 'ComplexTypeDemo')), new PhpWsdlMethod('PrintComplexType', array(new PhpWsdlParam('obj', 'ComplexTypeDemo')), new PhpWsdlParam('PrintComplexTypeResult', 'string')), new PhpWsdlMethod('ComplexTypeArrayDemo', array(new PhpWsdlParam('arr', 'ComplexTypeDemoArray')), new PhpWsdlParam('return', 'stringArray')), new PhpWsdlMethod('SayHello', array(new PhpWsdlParam('name', 'string')), new PhpWsdlParam('return', 'string')), new PhpWsdlMethod('DemoMethod')), array(new PhpWsdlComplex('ComplexTypeDemo', array(new PhpWsdlElement('StringA', 'string'), new PhpWsdlElement('StringB', 'string'), new PhpWsdlElement('Integer', 'int', array('nillable' => 'false')), new PhpWsdlElement('Boolean', 'boolean', array('nillable' => 'false')))), new PhpWsdlComplex('stringArray'), new PhpWsdlComplex('ComplexTypeDemoArray')), false, false);
// Don't start the SOAP server right now
// Disable caching for demonstration
ini_set('soap.wsdl_cache_enabled', 0);
// Disable caching in PHP
PhpWsdl::$CacheTime = 0;
// Disable caching in PhpWsdl
// Run the SOAP server
if ($soap->IsWsdlRequested()) {
    $soap->Optimize = false;
}
// Don't optimize WSDL to send it human readable to the browser
$soap->RunServer();
// Finally, run the server
示例#10
0
<?php

require_once 'Customer.php';
require_once 'CustomerInfo.php';
require_once 'php-wsdl/class.phpwsdl.php';
$script = 'http://localhost/soap/' . 'CustomerSoap.php';
$soap = PhpWsdl::CreateInstance(null, $script, './cache', array('Customer.php', 'CustomerInfo.php'), 'Customer', null, null, falce, false);
// Don't start the SOAP server right now
// Disable caching for demonstration
ini_set('soap.wsdl_cache_enabled', 0);
// Disable caching in PHP
PhpWsdl::$CacheTime = 0;
// Disable caching in PhpWsdl
// Run the SOAP server
if ($soap->IsWsdlRequested()) {
    // WSDL requested by the client?
    $soap->Optimize = false;
}
// Don't optimize WSDL to send it human readable to the browser
//$soap->ParseDocs=false;				// Uncomment this line to disable the whole documentation features
//$soap->IncludeDocs=false;				// Uncomment this line to disable writing the documentation in WSDL XML
//$wsdl=$soap->CreateWsdl();			// This would save the WSDL XML string in $wsdl
//$php=$soap->OutputPhp(false,false);	// This would save a PHP SOAP client as PHP source code string in $php
//$html=$soap->OutputHtml(false,false);	// This would save the HTML documentation string in $html
$soap->RunServer();