PHP Classes

File: samples-generator.php

Recommend this page to a friend!
  Classes of WsdlToPhp   WSDL To PHP   samples-generator.php   Download  
File: samples-generator.php
Role: Example script
Content type: text/plain
Description: Class source
Class: WSDL To PHP
Generate classes to send SOAP requests from a WSDL
Author: By
Last change: [UPDATE] PSR-2 standards for generator files and generated files
[UPDATE] enhancement and compliance

In order to let the PHP native SoapClient class handle correctly the
object to send based on the request created with the generated classes,
we no longer define the array to send. Indeed, it's better to let the
SoapClient convert the object passed to the generate method mathcing the
operation to call instead of defining an array based on the object. It
actually creates conflicts or defines values that should be sent.
By this update, the option sendArrayAsParameter should be not useful
anymore.
By this update we lose the faculty to define a specific behaviour on the
values sent because we previously called the getter associated to the
value to send. In this case, the generate method PHP doc block has been
simplified.

Update of the sample file to be more explicit on the optional parameter
when instantiating a Service class.

Finally, the sample case for PayPal in samples-generator.php has been
updated to give a functional example based on this update.
[UPDATE] enhancements and refactoring

Closes https://github.com/mikaelcom/WsdlToPhp/issues/25.

Simplification of the instantiation of Service objects in the
generated sample file by removing the SoapClient options parameter. By
default, the cache_wsdl is disabled, the wsdl_url is set with the WSDL
url used to generate the package and trace is set with true. The
VALUE_WSDL_URL constant has been added to the generated WsdlClass
defined with the WSDL url used to generate the package.

Remove trailing ?> in generator files/classes.

Add WsdlToPhpGenerator::getWsdl($_index) method to get any WSDL at any
position.

Enhance generated sample file with explanation about the optional
parameter allowing to override the SoapClient Options. Remove the $wsdl
parareter previously used to instantiate each Service object.

Avoid Struct object to reset SoapClient when it is instantiated when
calling the parent constructor.
[UPDATE] several updates based on Github updated files
[UPDATE] updates initiated by the pull request https://github.com/mikaelcom/WsdlToPhp/pull/11
Date: 9 years ago
Size: 6,054 bytes
 

Contents

Class file image Download
<?php
/**
 * Sample to show how to use WsdlToPhpGenerator class
 * @package WsdlToPhpGenerator
 * @date 01/07/2012
 */
ini_set('display_errors',true);
error_reporting(-1);
ini_set('memory_limit',-1);
/**
 * In case function lcfirst doesn't exist
 */
if(!function_exists('lcfirst'))
{
    function
lcfirst($_s)
    {
        return
strtolower(substr($_s,0,1)) . substr($_s,1);
    }
}
/**
 * Librairies
 */
$localDir = dirname(__FILE__) . '/';
require_once
$localDir . 'WsdlToPhpModel.php';
require_once
$localDir . 'WsdlToPhpStruct.php';
require_once
$localDir . 'WsdlToPhpService.php';
require_once
$localDir . 'WsdlToPhpFunction.php';
require_once
$localDir . 'WsdlToPhpGenerator.php';
require_once
$localDir . 'WsdlToPhpStructValue.php';
require_once
$localDir . 'WsdlToPhpStructAttribute.php';
/**
 * Cleaning tests
 */
if(false)
{
    echo
"\r\n Clean Name for '2And'is-go54 83od+*/you=yèçés_3' is " . WsdlToPhpModel::cleanString("2And'is-go54 83od+*/you=yéçès_3") . " \r\n";
    return;
}
/**
 * OVH SOAP API
 * Lots of structs and operations
 */
if(false)
{
   
$w = new WsdlToPhpGenerator('http://www.ovh.com/soapi/soapi-dlw-1.54.wsdl');
   
WsdlToPhpGenerator::setOptionGenerateAutoloadFile(true);
   
WsdlToPhpGenerator::setOptionGenerateWsdlClassFile(true);
   
WsdlToPhpGenerator::setOptionResponseAsWsdlObject(true);
   
WsdlToPhpGenerator::setOptionGenerateTutorialFile(true);
   
WsdlToPhpGenerator::setOptionCategory(WsdlToPhpGenerator::OPT_CAT_START_NAME);
   
WsdlToPhpGenerator::setOptionSubCategory(WsdlToPhpGenerator::OPT_SUB_CAT_END_NAME);
   
$w->generateClasses('ovh',dirname(__FILE__) . '/samples/ovh/');
}
/**
 * BING Web Search API
 */
if(false)
{
   
$w = new WsdlToPhpGenerator('http://api.bing.net/search.wsdl');
   
WsdlToPhpGenerator::setOptionGenerateAutoloadFile(true);
   
WsdlToPhpGenerator::setOptionGenerateWsdlClassFile(true);
   
WsdlToPhpGenerator::setOptionSendParametersAsArray(true);
   
WsdlToPhpGenerator::setOptionGenerateTutorialFile(true);
   
WsdlToPhpGenerator::setOptionCategory(WsdlToPhpGenerator::OPT_CAT_START_NAME);
   
WsdlToPhpGenerator::setOptionSubCategory(WsdlToPhpGenerator::OPT_SUB_CAT_END_NAME);
   
$w->generateClasses('bing',dirname(__FILE__) . '/samples/bing/');
}
/**
 * AT Internet
 */
if(false)
{
   
exec('rm -rf ' . __DIR__ . '/samples/at/*;');
   
$w = new WsdlToPhpGenerator('http://api.atinternet-solutions.com/toolbox/reporting.asmx?WSDL');
   
WsdlToPhpGenerator::setOptionGenerateAutoloadFile(true);
   
WsdlToPhpGenerator::setOptionGenerateWsdlClassFile(true);
   
WsdlToPhpGenerator::setOptionSendArrayAsParameter(true);
   
WsdlToPhpGenerator::setOptionGenerateTutorialFile(true);
   
WsdlToPhpGenerator::setOptionCategory(WsdlToPhpGenerator::OPT_CAT_START_NAME);
   
WsdlToPhpGenerator::setOptionSubCategory(WsdlToPhpGenerator::OPT_SUB_CAT_END_NAME);
   
$w->generateClasses('at',dirname(__FILE__) . '/samples/at/');
}
/**
 * Via michelin
 */
if(false)
{
   
$wsdls = array(
               
'Geocoding'=>'http://webservices.viamichelin.com/ws2/services/Geocoding?wsdl',
               
'ReverseGeocoding'=>'http://webservices.viamichelin.com/ws2/services/ReverseGeocoding?wsdl',
               
'RouteCalculation'=>'http://webservices.viamichelin.com/ws2/services/RouteCalculation?wsdl',
               
'FindPOI'=>'http://webservices.viamichelin.com/ws2/services/FindPOI?wsdl',
               
'DistanceCalculation'=>'http://webservices.viamichelin.com/ws2/services/DistanceCalculation?wsdl',
               
'MapManagement'=>'http://webservices.viamichelin.com/ws2/services/MapManagement?wsdl',
               
'AccessManagement'=>'https://webservices.viamichelin.com/ws2/services/AccessManagement?wsdl');
    foreach(
$wsdls as $name=>$wsdl)
    {
       
$name = 'ViaMichelin' . $name;
       
exec('rm -rf ' . __DIR__ . '/samples/' . $name . '/*;');
       
$w = new WsdlToPhpGenerator($wsdl);
       
WsdlToPhpGenerator::setOptionGenerateAutoloadFile(true);
       
WsdlToPhpGenerator::setOptionGenerateWsdlClassFile(true);
       
WsdlToPhpGenerator::setOptionResponseAsWsdlObject(true);
       
WsdlToPhpGenerator::setOptionGenerateTutorialFile(true);
       
WsdlToPhpGenerator::setOptionSendArrayAsParameter(false);
       
WsdlToPhpGenerator::setOptionSendParametersAsArray(false);
       
WsdlToPhpGenerator::setOptionCategory(WsdlToPhpGenerator::OPT_CAT_START_NAME);
       
WsdlToPhpGenerator::setOptionSubCategory(WsdlToPhpGenerator::OPT_SUB_CAT_END_NAME);
       
$w->generateClasses($name,dirname(__FILE__) . '/samples/' . $name . '/');
    }
}
/**
 * Any
 */
if(true)
{
   
$name = 'PayPal';
   
$wsdl = 'https://www.paypalobjects.com/wsdl/PayPalSvc.wsdl';
   
exec('rm -rf ' . __DIR__ . '/samples/' . $name . '/*;');
    echo
"\r\nStart at " . date('H:i:s');
   
$w = new WsdlToPhpGenerator($wsdl);
   
WsdlToPhpGenerator::setOptionGenerateAutoloadFile(true);
   
WsdlToPhpGenerator::setOptionGenerateWsdlClassFile(true);
   
WsdlToPhpGenerator::setOptionGenerateTutorialFile(true);
   
WsdlToPhpGenerator::setOptionCategory(WsdlToPhpGenerator::OPT_CAT_TYPE);
   
WsdlToPhpGenerator::setOptionSubCategory(WsdlToPhpGenerator::OPT_SUB_CAT_END_NAME);
   
WsdlToPhpGenerator::setOptionAddComments(array(
                                                   
'date'=>date('Y-m-d'),
                                                   
'author'=>'Mikaël DELSOL',
                                                   
'version'=>1));
    echo
"\r\nStart generation at " . date('H:i:s');
   
$w->generateClasses($name,dirname(__FILE__) . '/samples/' . $name . '/');
    echo
"\r\nEnd generation at " . date('H:i:s');
    echo
"\r\nGenerate doc start " . date('H:i:s');
   
$ouputs = array();
   
exec('rm -rf ' . __DIR__ . '/docs/' . $name . '/* && clear && phpdoc --sourcecode on -d ' . __DIR__ . '/samples/' . $name . ' -t ' . __DIR__ . '/docs/' . $name . ' -pp -ti "' . ucfirst($name) . ' package documentation" -o HTML:frames:DOM/earthli;',$ouputs);
   
print_r($ouputs);
    echo
"\r\nGenerate doc end " . date('H:i:s');
   
print_r($w->getAudit());
}