#!/usr/bin/env php

<?php
/**
 * Use [Wsdl2PhpGenerator](https://github.com/wsdl2phpgenerator/wsdl2phpgenerator) to generate PHP classes
 * from Omniva SOAP service(s)
 *
 * The generated classes will be put under src/Soap/Wsdl.
 * Run this program from the root directory of the project.
 */

use Bigbank\Omniva\Services\AddressSearch;
use Wsdl2PhpGenerator\Config;
use Wsdl2PhpGenerator\Generator;

require './vendor/autoload.php';

echo sprintf(
    "Generating WSDL files from Omniva service (%s). " .
    "This requires an active internet connection.\n",
    AddressSearch::PRODUCTION_API_URL
);

$generator = new Generator;
$config    = new Config([
    'inputFile'                      => AddressSearch::PRODUCTION_API_URL,
    'outputDir'                      => './src/Soap/Wsdl',
    'namespaceName'                  => 'Bigbank\Omniva\Soap\Wsdl',
    'sharedTypes'                    => true,
    'proxy'                          => getenv('HTTPS_PROXY'),
    // 'soapClientClass' value must begin with a leading namespace class
    // otherwise the generated class uses a relative namespace which won't resolve
    'soapClientClass'                => '\Bigbank\Omniva\Soap\ProxyAwareClient',
    'constructorParamsDefaultToNull' => true
]);

$generator->generate($config);

// Delete autoloader - it's not needed as we use Composer's
if (file_exists('./src/Soap/Wsdl/autoload.php')) {
    unlink('./src/Soap/Wsdl/autoload.php');
}
