Skip to content

Commit

Permalink
Merge pull request #1 from LeaseWeb/php7
Browse files Browse the repository at this point in the history
PHP7 only support
  • Loading branch information
nrocco committed Aug 9, 2018
2 parents cd3c424 + 7f519a7 commit d3d86c0
Show file tree
Hide file tree
Showing 52 changed files with 3,289 additions and 1,725 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

/vendor/
/build
/.php_cs.cache
5 changes: 5 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

$finder = PhpCsFixer\Finder::create()->in("src")->in("tests");

return PhpCsFixer\Config::create()->setRules(array('@PSR2' => true, '@Symfony' => true, 'concat_space' => false))->setFinder($finder);
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ clean:
# Test everything
.PHONY: test
test: clean
vendor/bin/phpunit -c tests/
vendor/bin/phpunit


.PHONY: phpmd
Expand Down
2 changes: 1 addition & 1 deletion TestService.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

require __DIR__.'/src/bootstrap.php';
require_once __DIR__.'/vendor/autoload.php';

ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache

Expand Down
77 changes: 67 additions & 10 deletions bin/compile
Original file line number Diff line number Diff line change
@@ -1,17 +1,74 @@
#!/usr/bin/env php
<?php

require __DIR__.'/../src/bootstrap.php';
require_once __DIR__.'/../vendor/autoload.php';

use PhpSoapClient\Compiler;
use Symfony\Component\Finder\Finder;

error_reporting(-1);
ini_set('display_errors', 1);
if (file_exists('soap_client.phar')) {
unlink('soap_client.phar');
}

function stripWhiteSpace($source)
{
$output = '';
foreach (token_get_all($source) as $token) {
if (is_string($token)) {
$output .= $token;
} elseif (in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) {
$output .= str_repeat("\n", substr_count($token[1], "\n"));
} elseif (T_WHITESPACE === $token[0]) {
// reduce wide spaces
$whitespace = preg_replace('{[ \t]+}', ' ', $token[1]);
// normalize newlines to \n
$whitespace = preg_replace('{(?:\r\n|\r|\n)}', "\n", $whitespace);
// trim leading spaces
$whitespace = preg_replace('{\n +}', "\n", $whitespace);
$output .= $whitespace;
} else {
$output .= $token[1];
}
}

return $output;
}

echo "==> Creating phar in soap_client.phar\n";

$phar = new \Phar('soap_client.phar', 0, 'soap_client.phar');
$phar->setSignatureAlgorithm(\Phar::SHA1);
$phar->startBuffering();

try {
$compiler = new Compiler();
$compiler->compile();
} catch (\Exception $e) {
echo 'Failed to compile phar: ['.get_class($e).'] '.$e->getMessage().' at '.$e->getFile().':'.$e->getLine();
exit(1);
$finder = new Finder();
$finder
->files()
->ignoreVCS(true)
->in(__DIR__.'/../bin')
->in(__DIR__.'/../config')
->in(__DIR__.'/../src')
->in(__DIR__.'/../vendor')
->exclude('Tests')
->exclude('tests')
->name('*.php')
->name('*.yml')
->name('console');

foreach ($finder as $file) {
$path = str_replace(dirname(__DIR__).DIRECTORY_SEPARATOR, '', $file->getRealPath());
$content = preg_replace('{^#!/usr/bin/env php\s*}', '', $file->getContents());
$phar->addFromString($path, stripWhiteSpace($content));
}

$phar->setStub("#!/usr/bin/env php
<?php
Phar::mapPhar('soap_client.phar');
require 'phar://soap_client.phar/bin/console';
__HALT_COMPILER();");

$phar->stopBuffering();
$phar->compressFiles(\Phar::GZ);

unset($phar);
chmod('soap_client.phar', 0755);

echo "==> Done creating phar archive\n";
25 changes: 25 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env php
<?php

use Symfony\Component\Config\FileLocator;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;

set_time_limit(0);

require_once __DIR__.'/../vendor/autoload.php';

$input = new ArgvInput();
$config = $input->getParameterOption(['--config', '-c'], $_SERVER['APP_CONFIG'] ?? 'soap_client.yml', true);

$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../config'));
$loader->load('app.yml');
$loader->load('parameters.yml');

if (file_exists($config)) {
$loader->load(realpath($config));
}

$container->get('symfony.application')->run($input, $container->get('symfony.console_output'));
49 changes: 0 additions & 49 deletions bin/soap_client

This file was deleted.

74 changes: 74 additions & 0 deletions completion.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#compdef soap_client

_soap_client () {
local curcontext="$curcontext" state line
typeset -A opt_args

local -a soap_client_commands
soap_client_commands=(
'call:Call the remote service with the `method` specified and output the reponse to stdout.'
'list-methods:Get a list of available methods to call on the remote.'
'request:Generate an xml formatted SOAP request for the given method and output to stdout.'
'wsdl:Get the WSDL of a soap service.'
)

_arguments -C \
'--config=[The location to the configuration file]:filename:_files' \
'--endpoint=[Specify the url to the wsdl of the SOAP webservice to inspect]:args' \
'--proxy=[Use this proxy to connect to the SOAP web service]:args' \
'--quiet[Do not output any message]' \
'--cache[Enable caching of the wsdl]' \
'1: :{_describe "commands" soap_client_commands}' \
'*::args:->args'

case $state in
(args)
case $line[1] in
(call)
_soap_client-call
;;
(request)
_soap_client-request
;;
esac
;;
esac
}

_soap_client-call () {
local curcontext="$curcontext" state line
typeset -A opt_args

_arguments -C \
"--editor[Open the request xml in your favorite $EDITOR before sending to the server]" \
"--xml[Output the results as xml. Otherwise output as an object]" \
'1: :_soap_client-methods'
}

_soap_client-request () {
local curcontext="$curcontext" state line
typeset -A opt_args

_arguments -C \
'1: :_soap_client-methods'
}

_soap_client-methods () {
local endpoint

for token in $tokens; do
if [[ "$token" =~ ^--endpoint=.* ]]
then
endpoint=$token
break
fi
done

[[ -z $endpoint ]] && return 1

local -a soap_client_methods
soap_client_methods=($($name --cache ${endpoint//\"/} list-methods))
_describe "methods" soap_client_methods
}

_soap_client "$@"
36 changes: 22 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,33 @@
"name": "leaseweb/phpsoapclient",
"description": "A CLI PHP Soap Client",
"license": "BSD-4-Clause",
"require": {
"php": ">=7.0.0",
"symfony/config": "^3.4",
"symfony/console": "^3.4",
"symfony/dependency-injection": "^3.4",
"symfony/event-dispatcher": "^3.4",
"symfony/finder": "^3.4",
"symfony/yaml": "^3.4",
"psr/log": "^1.0"
},
"bin": [
"bin/console"
],
"require-dev": {
"piotrooo/wsdl-creator": "1.0.0",
"friendsofphp/php-cs-fixer": "^2.10",
"phpunit/phpunit": "^7.0"
},
"authors": [
{
"name": "Nico Di Rocco",
"email": "n.dirocco@ocom.com"
"email": "n.dirocco@global.leaseweb.com"
}
],
"minimum-stability": "stable",
"require": {
"symfony/console": "v2.3.2",
"symfony/finder": "v2.3.2",
"silex/silex": "1.*"
},
"require-dev": {
"phpunit/phpunit": "3.7.22",
"phpmd/phpmd" : "1.4.*",
"squizlabs/php_codesniffer": "1.*",
"piotrooo/wsdl-creator": "1.0.0"
},
"autoload": {
"psr-0": {"": "src/"}
"psr-4": {
"App\\": "src/"
}
}
}
Loading

0 comments on commit d3d86c0

Please sign in to comment.