/** * Constructor * * @param string $name The name * @param array $settings Settings array (default: NULL) */ public function PhpWsdlObject($name, $settings = null) { $this->GUID = uniqid(); PhpWsdl::Debug('New PhpWsdlObject "' . $name . '" with GUID "' . $this->GUID . '"'); $this->Name = $name; if (!is_null($settings)) { if (isset($settings['docs'])) { $this->Docs = $settings['docs']; } if (isset($settings['settings'])) { $this->Settings = $settings['settings']; } } }
public function __call($method, $param) { if (PhpWsdl::$Debugging) { PhpWsdl::Debug('Proxy call method ' . $method . ': ' . print_r($param, true)); } PhpWsdl::$ProxyServer->CreateWsdl(); $m = PhpWsdl::$ProxyServer->GetMethod($method); if (is_null($m)) { throw new SoapFault('MissingMethod', 'Method "' . $method . '" not found'); } // Try to fix the missing parameters issue if the SoapServer is not running in WSDL mode if (!PhpWsdl::$UseProxyWsdl) { $pLen = sizeof($m->Param); $temp = sizeof($param); if ($pLen != $temp) { PhpWsdl::Debug('Wrong parameter count (' . $temp . '/' . $pLen . ')'); $req = new DOMDocument(); if ($req->loadXml(file_get_contents('php://input'))) { $x = new DOMXPath($req); $temp = $param; $param = array(); $pos = 0; // Current index in the received parameter array $i = -1; while (++$i < $pLen) { $p = $m->Param[$i]; if ($x->query("/*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='" . $m->Name . "']/*[local-name()='" . $p->Name . "']")->length > 0) { PhpWsdl::Debug('Parameter "' . $p->Name . '" was received'); $param[] = $temp[$pos]; $pos++; } else { PhpWsdl::Debug('Parameter "' . $p->Name . '" was missing'); $param[] = null; } } } else { PhpWsdl::Debug('Could not parse SOAP request XML'); } } } // Prepare the method call $call = $m->IsGlobal ? $method : array(is_null($m->Class) ? PhpWsdl::$ProxyObject : $m->Class, $method); // Call the target method PhpWsdl::Debug('Call the target method'); $res = sizeof($param) < 1 ? call_user_func($call) : call_user_func_array($call, $param); // Return the encoded response $type = is_null($m->Return) ? null : $m->Return->Name; return PhpWsdl::$EncodeProxyReturn && !is_null($type) ? PhpWsdl::DoEncoding($type, $res, false, PhpWsdl::$ProxyServer) : $res; }
/** * This will forward a request to another URI, output the response and exit * * @param string $targetUri The target URI */ public static function RunForwarder($targetUri) { require_once dirname(__FILE__) . '/class.phpwsdl.php'; PhpWsdl::Debug('Run PhpWsdlAjax forwarder at ' . $targetUri); if ($_SERVER['REQUEST_METHOD'] == 'GET') { PhpWsdl::Debug('Forward GET request'); ob_start('ob_gzhandler'); echo self::HttpRequest(isset($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '', null, $targetUri); } else { PhpWsdl::Debug('Forward POST request'); ob_start('ob_gzhandler'); echo self::HttpRequest(null, file_get_contents('php://input'), $targetUri); } exit; }
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(); }
/** * Create a Zend soap_server object * * @param PhpWsdl $server The PhpWsdl object * @param array $data Hook data (default: NULL) * @return Zend_Soap_Server The Zend server object */ public static function CreateServer($server, $data = null) { if (!is_null(self::$Server)) { return self::$Server; } self::$Server = new Zend_Soap_Server(!is_null($server->WsdlUri) ? $server->WsdlUri : $server->EndPoint . '?WSDL', array_merge(self::$Options, array('actor' => $server->EndPoint, 'wsdl' => $server->CreateWsdl(), 'uri' => $server->NameSpace))); if (!is_null($data)) { if (PhpWsdl::CallHook('ZendConfigHook', $data)) { if (is_object($data['class'])) { $this->Server->setObject($data['class']); } else { $this->Server->setClass($data['class']); } } } }
<?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 { /**
<?php require_once '../php-wsdl/class.phpwsdl.php'; //require_once ('ControllerSoap.php'); //require_once ('../controller/ControllerDataStruct.php'); PhpWsdl::RunQuickMode(array('ControllerSoap.php', '../controller/ControllerDataStruct.php'));
/** * Create complex type object * * @param array $data The parser data * @return boolean Response */ public static function CreateComplexTypeObject($data) { if ($data['method'] != '') { return true; } if (!is_null($data['obj'])) { return true; } if (!is_array($data['type'])) { return true; } if (!isset($data['type']['id'])) { return true; } if ($data['type']['id'] != 'complex') { return true; } if (!is_null($data['docs'])) { $data['settings']['docs'] = $data['docs']; } else { $data['settings']['docs'] = $data['type']['docs']; } PhpWsdl::Debug('Add complex type ' . $data['type']['name']); $data['settings']['isarray'] = !is_null($data['type']['type']); $data['obj'] = new PhpWsdlComplex($data['type']['name'], $data['elements'], $data['settings']); $data['obj']->Type = $data['type']['type']; $data['settings'] = array(); $data['server']->Types[] = $data['obj']; return true; }
/** * Interpret a element keyword * * @param array $data The parser data * @return boolean Response */ public static function InterpretElement($data) { $info = explode(' ', $data['keyword'][1], 3); if (sizeof($info) < 2) { return true; } $name = substr($info[1], 1); if (substr($name, strlen($name) - 1, 1) == ';') { $name = substr($name, 0, strlen($name) - 1); } PhpWsdl::Debug('Interpret element ' . $name); if ($data['server']->ParseDocs) { if (sizeof($info) > 2) { $data['settings']['docs'] = trim($info[2]); } } $data['elements'][] = new PhpWsdlElement($name, $info[0], $data['settings']); $data['settings'] = array(); return false; }
<?php require_once 'php-wsdl-2.3/class.phpwsdl.php'; PhpWsdl::RunQuickMode('ServiceFunctions.php');
/** * Create method object * * @param array $data The parser data * @return boolean Response */ public static function CreateMethodObject($data) { if (!is_null($data['obj'])) { return true; } if ($data['method'] == '') { return true; } if (!is_null($data['type'])) { return true; } PhpWsdl::Debug('Add method ' . $data['method']); $server = $data['server']; if (!is_null($server->GetMethod($data['method']))) { PhpWsdl::Debug('WARNING: Double method detected!'); return true; } if ($server->ParseDocs) { if (!is_null($data['docs'])) { $data['settings']['docs'] = $data['docs']; } } $data['obj'] = new PhpWsdlMethod($data['method'], $data['param'], $data['return'], $data['settings']); $data['settings'] = array(); $server->Methods[] = $data['obj']; return true; }
/** * Initialize PhpWsdl */ public static function Init() { self::Debug('Init'); // Configuration self::$HTML2PDFSettings = array('attachments' => '1', 'outline' => '1'); self::$NameSpaces = array('soap' => 'http://schemas.xmlsoap.org/wsdl/soap/', 's' => 'http://www.w3.org/2001/XMLSchema', 'wsdl' => 'http://schemas.xmlsoap.org/wsdl/', 'soapenc' => 'http://schemas.xmlsoap.org/soap/encoding/'); self::EnableCache(); self::$Config['extensions'] = array(); // A configuration space for extensions self::$Config['tns'] = 'tns'; // The xmlns name for the target namespace self::$Config['xsd'] = 's'; // The xmlns name for the XSD namespace // Parser hooks self::RegisterHook('InterpretKeywordserviceHook', 'internal', 'PhpWsdl::InterpretService'); // WSDL hooks self::RegisterHook('CreateWsdlHeaderHook', 'internal', 'PhpWsdl::CreateWsdlHeader'); self::RegisterHook('CreateWsdlTypeSchemaHook', 'internal', 'PhpWsdl::CreateWsdlTypeSchema'); self::RegisterHook('CreateWsdlMessagesHook', 'internal', 'PhpWsdl::CreateWsdlMessages'); self::RegisterHook('CreateWsdlPortsHook', 'internal', 'PhpWsdl::CreateWsdlPorts'); self::RegisterHook('CreateWsdlBindingsHook', 'internal', 'PhpWsdl::CreateWsdlBindings'); self::RegisterHook('CreateWsdlServiceHook', 'internal', 'PhpWsdl::CreateWsdlService'); self::RegisterHook('CreateWsdlFooterHook', 'internal', 'PhpWsdl::CreateWsdlFooter'); self::RegisterHook('CreateWsdlOptimizeHook', 'internal', 'PhpWsdl::CreateWsdlOptimize'); // HTML hooks self::RegisterHook('CreateHtmlGeneralHook', 'internal', 'PhpWsdl::CreateHtmlGeneral'); self::RegisterHook('CreateHtmlIndexHook', 'internal', 'PhpWsdl::CreateHtmlIndex'); self::RegisterHook('CreateHtmlMethodsHook', 'internal', 'PhpWsdl::CreateHtmlMethods'); self::RegisterHook('CreateHtmlComplexTypesHook', 'internal', 'PhpWsdl::CreateHtmlComplexTypes'); // Extensions self::Debug('Load extensions'); $files = glob(dirname(__FILE__) . '/' . 'class.phpwsdl.*.php'); if ($files !== false) { $i = -1; $len = sizeof($files); while (++$i < $len) { self::Debug('Load ' . $files[$i]); require_once $files[$i]; } } else { self::Debug('"glob" failed'); } }
<?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'));
/** * Initialize PhpWsdl */ public static function Init() { self::Debug('Init'); // Configuration self::$HTML2PDFSettings = array('attachments' => '1', 'outline' => '1'); self::$NameSpaces = array('soap' => 'http://schemas.xmlsoap.org/wsdl/soap/', 's' => 'http://www.w3.org/2001/XMLSchema', 'wsdl' => 'http://schemas.xmlsoap.org/wsdl/', 'soapenc' => 'http://schemas.xmlsoap.org/soap/encoding/'); //TODO How to encode the missing basic types? self::$TypeEncoding = array('parameter' => array(), 'return' => array(), 'default' => array('string' => array('encoding' => XSD_STRING), 'boolean' => array('encoding' => XSD_BOOLEAN), 'decimal' => array('encoding' => XSD_DECIMAL), 'float' => array('encoding' => XSD_FLOAT), 'double' => array('encoding' => XSD_DOUBLE), 'duration' => array('encoding' => XSD_DURATION), 'dateTime' => array('encoding' => XSD_DATETIME), 'time' => array('encoding' => XSD_TIME), 'date' => array('encoding' => XSD_DATE), 'gYearMonth' => array('encoding' => XSD_GYEARMONTH), 'gYear' => array('encoding' => XSD_GYEAR), 'gMonthDay' => array('encoding' => XSD_GMONTHDAY), 'gDay' => array('encoding' => XSD_GDAY), 'gMonth' => array('encoding' => XSD_GMONTH), 'hexBinary' => array('encoding' => XSD_HEXBINARY), 'base64Binary' => array('encoding' => XSD_BASE64BINARY), 'anyURI' => array('encoding' => XSD_ANYURI), 'QName' => array('encoding' => XSD_QNAME), 'NOTATION' => array('encoding' => XSD_NOTATION), 'int' => array('encoding' => XSD_INT), 'integer' => array('encoding' => XSD_INTEGER), 'long' => array('encoding' => XSD_LONG), 'short' => array('encoding' => XSD_SHORT), 'byte' => array('encoding' => XSD_BYTE), 'anyType' => array('encoding' => XSD_ANYTYPE))); self::EnableCache(); self::$Config['extensions'] = array(); // A configuration space for extensions self::$Config['tns'] = 'tns'; // The xmlns name for the target namespace self::$Config['xsd'] = 's'; // The xmlns name for the XSD namespace // Parser hooks self::RegisterHook('InterpretKeywordserviceHook', 'internal', 'PhpWsdl::InterpretService'); self::RegisterHook('InterpretKeywordpw_setHook', 'internal', 'PhpWsdl::InterpretSetting'); // WSDL hooks self::RegisterHook('CreateWsdlHeaderHook', 'internal', 'PhpWsdl::CreateWsdlHeader'); self::RegisterHook('CreateWsdlTypeSchemaHook', 'internal', 'PhpWsdl::CreateWsdlTypeSchema'); self::RegisterHook('CreateWsdlMessagesHook', 'internal', 'PhpWsdl::CreateWsdlMessages'); self::RegisterHook('CreateWsdlPortsHook', 'internal', 'PhpWsdl::CreateWsdlPorts'); self::RegisterHook('CreateWsdlBindingsHook', 'internal', 'PhpWsdl::CreateWsdlBindings'); self::RegisterHook('CreateWsdlServiceHook', 'internal', 'PhpWsdl::CreateWsdlService'); self::RegisterHook('CreateWsdlFooterHook', 'internal', 'PhpWsdl::CreateWsdlFooter'); self::RegisterHook('CreateWsdlOptimizeHook', 'internal', 'PhpWsdl::CreateWsdlOptimize'); // HTML hooks self::RegisterHook('CreateHtmlGeneralHook', 'internal', 'PhpWsdl::CreateHtmlGeneral'); self::RegisterHook('CreateHtmlIndexHook', 'internal', 'PhpWsdl::CreateHtmlIndex'); self::RegisterHook('CreateHtmlMethodsHook', 'internal', 'PhpWsdl::CreateHtmlMethods'); self::RegisterHook('CreateHtmlComplexTypesHook', 'internal', 'PhpWsdl::CreateHtmlComplexTypes'); // Extensions self::Debug('Load extensions'); $files = glob(dirname(__FILE__) . '/' . 'class.phpwsdl.*.php'); if ($files !== false) { $i = -1; $len = sizeof($files); while (++$i < $len) { self::Debug('Load ' . $files[$i]); require_once $files[$i]; } } else { self::Debug('"glob" failed'); } }
/** * Create enumeration object * * @param array $data The parser data * @return boolean Response */ public static function CreateEnumTypeObject($data) { if ($data['method'] != '') { return true; } if (!is_null($data['obj'])) { return true; } if (!is_array($data['type'])) { return true; } if (!isset($data['type']['id'])) { return true; } if ($data['type']['id'] != 'enum') { return true; } if (!isset($data['type']['elements'])) { return true; } if (!is_array($data['type']['elements'])) { return true; } if (!is_null($data['docs'])) { $data['settings']['docs'] = $data['docs']; } else { $data['settings']['docs'] = $data['type']['docs']; } PhpWsdl::Debug('Add enumeration ' . $data['type']['name']); $data['obj'] = new PhpWsdlEnum($data['type']['name'], $data['type']['type'], $data['type']['elements'], $data['settings']); $data['settings'] = array(); $data['server']->Types[] = $data['obj']; return true; }
/** * 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; }
<?php // This demonstrates the usage of the NuSOAP adapter. It requires the // PhpWsdl framework files to be in the same folder as this file. // // Note: The NuSOAP adapter won't work with the PhpWsdlProxy! // Load NoSOAP require_once 'nusoap.php'; // Change this to the location of your NuSOAP installation // Load PhpWsdl require_once 'class.phpwsdl.php'; // Load the NuSOAP 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('PhpWsdlNuSOAP')) { require_once 'class.phpwsdl.nusoap.php'; } // Run the SOAP server in quick mode $soap = PhpWsdl::RunQuickMode(array('class.soapdemo.php', 'class.complextypedemo.php')); // I was able to use this webservice with SoapUI. But with Visual Studio 2010 // I didn't receive the response. I think the problem may be the dot in the // response XML tag names that are produced by NuSOAP when registering a // method of a class. But without the dot NuSOAP won't find the method. There // is no way to change the class->method delimiter in NuSOAP (or you need to // touch their code). So I'm sorry, but this may not work with .NET clients... // // A solution for this problem would be to use only global methods. Then // Visual Studio would be able to consume the webservice.
/** * Decode a parameter or a return value * * @param string $type The type name * @param mixed $value The value to be decoded * @param boolean $parameter Is this a parameter value? (default: FALSE) * @return mixed The decoded value */ public static function DecodeType($type, $value, $parameter = false) { $res = null; $data = array('type' => &$type, 'value' => &$value, 'parameter' => &$parameter, 'res' => &$res); if (!PhpWsdl::CallHook('DecodeTypeHook', $data)) { return $res; } if (!PhpWsdl::CallHook('DecodeType' . ($parameter ? 'Parameter' : 'Return') . 'Hook', $data)) { return $res; } if (in_array($type, PhpWsdl::$BasicTypes)) { return $value; } $t = self::$UseServer->Server->GetType($type); if (is_null($t)) { throw new Exception('Could not decode type "' . $type . '"'); } if (get_class($t) == 'PhpWsdlEnum') { $type = $t->Type; } return in_array($type, PhpWsdl::$BasicTypes) ? $value : json_decode($value); }
<?php // A quick and dirty SOAP server example ini_set('soap.wsdl_cache_enabled', 0); // Disable caching in PHP $PhpWsdlAutoRun = true; // With this global variable PhpWsdl will autorun in quick mode, too require_once 'class.phpwsdl.php'; // When autorun is enabled, any line after loading PhpWsdl won't be executed! // In quick mode you can specify the class filename(s) of your webservice // optional parameter, if required. The next line will only be executed when // not using autorun. PhpWsdl::RunQuickMode(); // -> Don't waste my time - just run! class SoapDemo { /** * Say hello to... * * @param string $name A name * @return string Response */ public function SayHello($name) { $name = utf8_decode($name); if ($name == '') { $name = 'unknown'; } return utf8_encode('Hello ' . $name . '!'); } }
<?php ini_set("soap.wsdl_cache_enabled", "0"); require_once 'phpwsdl/class.phpwsdl.php'; include_once 'class.book.php'; include_once 'class.myservice.php'; PhpWsdl::RunQuickMode(array('class.myservice.php', 'class.book.php')); /* $soap=PhpWsdl::CreateInstance( null, // PhpWsdl will determine a good namespace null, // Change this to your SOAP endpoint URI (or keep it NULL and PhpWsdl will determine it) './cache', // Change this to a folder with write access Array( // All files with WSDL definitions in comments 'class.myservice.php', 'class.book.php' ), null, // The name of the class that serves the webservice will be determined by PhpWsdl null, // This demo contains all method definitions in comments null, // This demo contains all complex types in comments false, // Don't send WSDL right now 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
/** * Write WSDL to cache * * @param string $wsdl The UTF-8 encoded WSDL string (default: NULL) * @param string $wsdluri The SOAP WSDL URI or NULL to use the default (default: NULL) * @param string $file The target filename or NULL to use the default (default: NULL) * @param boolean $force Force refresh (default: FALSE) * @return boolean Succeed? */ public function WriteWsdlToCache($wsdl = null, $wsdluri = null, $file = null, $force = false) { PhpWsdl::Debug('Write WSDL to the cache'); if (is_null($wsdluri)) { $wsdluri = $this->WsdlUri; } if ($wsdluri == $this->WsdlUri && !is_null($wsdl)) { $this->WSDL = $wsdl; } if (is_null($wsdl)) { if (is_null($this->WSDL)) { PhpWsdl::Debug('No WSDL'); return false; // WSDL not defined } $wsdl = $this->WSDL; } if (is_null($file)) { $file = $this->GetCacheFileName($wsdluri); if (is_null($file)) { PhpWsdl::Debug('No cache file'); return false; // No cache file } } $temp = substr($file, 0, 1); if ($temp != '/' && $temp != '.') { if (is_null(PhpWsdl::$CacheFolder)) { PhpWsdl::Debug('No cache folder'); return false; // No cache folder } $file = PhpWsdl::$CacheFolder . '/' . $file; } if (!$force) { if ($this->IsCacheValid($file)) { PhpWsdl::Debug('Cache is still valid'); return true; // Existing cache is still valid } } PhpWsdl::Debug('Write to ' . $file); if (file_put_contents($file, $wsdl) === false) { PhpWsdl::Debug('Could not write to cache'); return false; // Error writing to cache } if (file_put_contents($file . '.cache', time()) === false) { PhpWsdl::Debug('Could not write cache time file'); return false; // Error writing to cache } $data = array('version' => self::$VERSION, 'servicename' => $this->ServiceName, 'endpoint' => $this->EndPoint, 'namespace' => $this->NameSpace); PhpWsdl::CallHook('ClientWriteCacheHook', array('client' => $this, 'data' => &$data)); if (file_put_contents($file . '.obj', serialize($data)) === false) { PhpWsdl::Debug('Could not write serialized cache'); return false; } return true; }
<?php require_once 'GeneradorWSDL/class.phpwsdl.php'; //incluimos el archivo del paquete que utilizaremos para generar el wsdl PhpWsdl::RunQuickMode("Operaciones.php"); //referenciamos el archivo (clase) a partir del cual crearemos el wsdl, registrando en él las operaciones, tipos de datos, etc
// 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 * * @return string Response * @pw_set global=1 -> Tell PhpWsdl to serve this as global method (outside of a class) */ function GlobalMethodDemo() {
/** * Interpret a return value * * @param array $data The parser data * @return boolean Response */ public static function InterpretReturn($data) { if ($data['method'] == '') { return true; } $info = explode(' ', $data['keyword'][1], 2); if (sizeof($info) < 1) { return true; } PhpWsdl::Debug('Interpret return'); if ($data['server']->ParseDocs) { if (sizeof($info) > 1) { $data['settings']['docs'] = trim($info[1]); } } $data['return'] = new PhpWsdlParam(str_replace('%method%', $data['method'], self::$DefaultReturnName), $info[0], $data['settings']); $data['settings'] = array(); return false; }
/** * Interpret a WSDL definition * * @param string $def WSDL definition * @param string $method Method name */ public function InterpretDefinition($def, $method, $keywords, $docs) { PhpWsdl::Debug('Interpret definition'); if (!PhpWsdl::CallHook('BeforeInterpretDefinitionHook', array('sender' => $this, 'server' => $this->Server, 'def' => &$def, 'method' => &$method, 'keywords' => &$keywords, 'docs' => &$docs))) { return null; } // Initialize some variables $param = array(); // List ob parameter objects $return = null; // The return value object $elements = array(); // List of element objects $settings = array(); // Settings hash $omit = false; // Omit the object $type = null; // Type identifier $buffer = array(); // Other data // Interpret keywords $i = -1; $len = sizeof($keywords); while (++$i < $len) { $keyword = $keywords[$i]; if (PhpWsdl::$Debugging) { PhpWsdl::Debug('Interpret keyword ' . print_r($keyword, true)); } // Call the global keyword handler if (!PhpWsdl::CallHook('InterpretKeywordHook', array('sender' => $this, 'server' => $this->Server, 'def' => &$def, 'method' => &$method, 'keywords' => &$keywords, 'docs' => &$docs, 'param' => &$param, 'elements' => &$elements, 'return' => &$return, 'settings' => &$settings, 'omit' => &$omit, 'keyword' => &$keyword, 'type' => &$type, 'buffer' => &$buffer, 'newkeyword' => &$newkeyword))) { continue; } if ($omit) { return null; } // Call the keyword handler if (!PhpWsdl::CallHook('InterpretKeyword' . $keyword[0] . 'Hook', array('sender' => $this, 'server' => $this->Server, 'def' => &$def, 'method' => &$method, 'keywords' => &$keywords, 'docs' => &$docs, 'param' => &$param, 'elements' => &$elements, 'return' => &$return, 'settings' => &$settings, 'omit' => &$omit, 'keyword' => &$keyword, 'type' => &$type, 'buffer' => &$buffer, 'newkeyword' => &$newkeyword))) { continue; } if ($omit) { return null; } PhpWsdl::Debug('Keyword not handled'); } // Create object $obj = null; if (!PhpWsdl::CallHook('CreateObjectHook', array('sender' => $this, 'server' => $this->Server, 'def' => &$def, 'method' => &$method, 'keywords' => &$keywords, 'docs' => &$docs, 'param' => &$param, 'elements' => &$elements, 'return' => &$return, 'settings' => &$settings, 'omit' => &$omit, 'type' => &$type, 'buffer' => &$buffer, 'obj' => &$obj))) { return null; } if (!PhpWsdl::CallHook('AfterInterpretDefinitionHook', array('sender' => $this, 'server' => $this->Server, 'def' => &$def, 'method' => &$method, 'keywords' => &$keywords, 'docs' => &$docs, 'param' => &$param, 'elements' => &$elements, 'return' => &$return, 'settings' => &$settings, 'omit' => &$omit, 'type' => &$type, 'buffer' => &$buffer, 'obj' => &$obj))) { return null; } PhpWsdl::Debug('Object ' . (is_null($obj) ? 'not created' : 'created')); return $obj; }
<?php // This is an example specially for the REST server // Load PhpWsdl require_once 'class.phpwsdl.php'; // Load the servers 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 those lines: if (!class_exists('PhpWsdlServers')) { require_once 'class.phpwsdl.servers.php'; } if (!class_exists('PhpWsdlJavaScriptPacker')) { require_once 'class.phpwsdl.servers-jspacker.php'; } // This disables response compression (some servers don't support that) PhpWsdlServers::$EnableCompression = false; // Run the PhpWsdl server in quick mode /*PhpWsdl::$Debugging=true; PhpWsdl::$DebugFile=PhpWsdl::$CacheFolder.'/debug.log';*/ PhpWsdl::RunQuickMode('class.restdemo.php');