Skip to content

Commit 5256d50

Browse files
authored
Merge pull request #1 from gregurco/init
Init
2 parents cbe9b61 + 3771450 commit 5256d50

File tree

13 files changed

+599
-0
lines changed

13 files changed

+599
-0
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Ignore potentially sensitive phpunit file
2+
/phpunit.xml
3+
4+
# Ignore composer generated files
5+
/composer.lock
6+
/vendor/
7+
8+
# Ignore generated files
9+
/build/

.travis.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
language: php
2+
3+
sudo: false
4+
5+
php:
6+
- 7.0
7+
- 7.1
8+
9+
env:
10+
- SYMFONY_VERSION=3.2.*
11+
- SYMFONY_VERSION=3.3.*
12+
13+
cache:
14+
directories:
15+
- $HOME/.composer/cache/files
16+
17+
before_install:
18+
- composer self-update
19+
- composer config --global github-oauth.github.com ${GITHUB_TOKEN}
20+
21+
install:
22+
- composer install
23+
24+
script:
25+
- mkdir -p build/logs
26+
- php vendor/bin/phpunit -c phpunit.xml.dist --coverage-text
27+
28+
after_success:
29+
- travis_retry php vendor/bin/coveralls
30+
31+
notifications:
32+
email:
33+
- "gregurco.vlad@gmail.com"

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2017 Gregurco
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
Guzzle Bundle WSSE Plugin
2+
==================
3+
4+
[![Build Status](https://travis-ci.org/gregurco/GuzzleBundleWssePlugin.svg?branch=master)](https://travis-ci.org/gregurco/GuzzleBundleWssePlugin) [![Coverage Status](https://coveralls.io/repos/gregurco/GuzzleBundleWssePlugin/badge.svg?branch=master)](https://coveralls.io/r/gregurco/GuzzleBundleWssePlugin)
5+
6+
This plugin integrates [WSSE][1] functionality into Guzzle Bundle, a bundle for building RESTful web service clients.
7+
8+
9+
Requirements
10+
------------
11+
- PHP 7.0 or above
12+
- [Guzzle Bundle][2]
13+
14+
15+
Installation
16+
------------
17+
Using [composer][3]:
18+
19+
``` json
20+
{
21+
"require": {
22+
"gregurco/guzzle-bundle-wsse-plugin": "dev-master"
23+
}
24+
}
25+
```
26+
27+
28+
Usage
29+
-----
30+
Load plugin in AppKernel.php:
31+
``` php
32+
new EightPoints\Bundle\GuzzleBundle\EightPointsGuzzleBundle([
33+
new Gregurco\Bundle\GuzzleBundleWssePlugin\GuzzleBundleWssePlugin(),
34+
])
35+
```
36+
37+
Configuration in config.yml:
38+
``` yaml
39+
eight_points_guzzle:
40+
clients:
41+
api_payment:
42+
base_url: "http://api.domain.tld"
43+
44+
# define headers, options
45+
46+
# plugin settings
47+
plugin:
48+
wsse:
49+
username: "acme"
50+
password: "pa55w0rd"
51+
created_at: "-10 seconds" # optional
52+
```
53+
54+
Or use with guzzle directly:
55+
``` php
56+
<?php
57+
# Optional: Set third parameter by a expression (if not, current time will be used automatically)
58+
# http://php.net/manual/en/datetime.formats.relative.php
59+
# Useful if there is a small difference of time between client and server
60+
# DateTime object will be regenerated for every request
61+
$wsse = new \Gregurco\Bundle\GuzzleBundleWssePlugin\Middleware\WsseAuthMiddleware($username, $password);
62+
63+
$stack = \GuzzleHttp\HandlerStack::create();
64+
65+
// Add the wsse middleware to the handler stack.
66+
$stack->push($wsse->attach());
67+
68+
$client = new \GuzzleHttp\Client(['handler' => $stack]);
69+
$response = $client->get('http://www.8points.de');
70+
```
71+
72+
License
73+
-------
74+
This middleware is licensed under the MIT License - see the LICENSE file for details
75+
76+
[1]: http://www.xml.com/pub/a/2003/12/17/dive.html
77+
[2]: https://github.com/8p/GuzzleBundle
78+
[3]: https://getcomposer.org/

composer.json

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"name": "gregurco/guzzle-bundle-wsse-plugin",
3+
"type": "library",
4+
"description": "WSSE Plugin for Guzzle Bundle, a PHP HTTP client library and framework for building RESTful web service clients",
5+
"keywords": ["wsse", "middleware", "plugin", "framework", "http", "rest", "web service", "curl", "client", "HTTP client"],
6+
"homepage": "https://github.com/gregurco/GuzzleBundleWssePlugin",
7+
"license": "MIT",
8+
9+
"authors": [
10+
{
11+
"name": "Gregurco Vlad",
12+
"email": "gregurco.vlad@gmail.com",
13+
"homepage": "https://github.com/gregurco"
14+
},
15+
{
16+
"name": "Community",
17+
"homepage": "https://github.com/gregurco/GuzzleBundleWssePlugin/contributors"
18+
}
19+
],
20+
21+
"require": {
22+
"php": "^7.0",
23+
"guzzlehttp/guzzle": "^6.0",
24+
"eightpoints/guzzle-bundle": "dev-master",
25+
"symfony/http-kernel": "~2.3|~3.0",
26+
"symfony/config": "~2.3|~3.0",
27+
"symfony/dependency-injection": "~2.3|~3.0",
28+
"symfony/expression-language": "~2.3|~3.0"
29+
},
30+
31+
"require-dev": {
32+
"phpunit/phpunit": "~6.1",
33+
"satooshi/php-coveralls": "~1.0"
34+
},
35+
36+
"autoload": {
37+
"psr-4": {
38+
"Gregurco\\Bundle\\GuzzleBundleWssePlugin\\": "src"
39+
}
40+
},
41+
42+
"autoload-dev": {
43+
"psr-4": {
44+
"Gregurco\\Bundle\\GuzzleBundleWssePlugin\\Tests\\": "tests"
45+
}
46+
}
47+
}

phpunit.xml.dist

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
bootstrap="vendor/autoload.php"
4+
colors="true"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.1/phpunit.xsd"
7+
>
8+
<testsuites>
9+
<testsuite name="GuzzleBundleWssePlugin Test Suite">
10+
<directory>./tests</directory>
11+
</testsuite>
12+
</testsuites>
13+
14+
<filter>
15+
<whitelist>
16+
<directory>./src</directory>
17+
<exclude>
18+
<directory>./src/Resources/</directory>
19+
</exclude>
20+
</whitelist>
21+
</filter>
22+
23+
<logging>
24+
<log type="coverage-clover" target="build/logs/clover.xml"/>
25+
</logging>
26+
</phpunit>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Gregurco\Bundle\GuzzleBundleWssePlugin\DependencyInjection;
4+
5+
use Symfony\Component\DependencyInjection\ContainerBuilder;
6+
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
7+
use Symfony\Component\Config\FileLocator;
8+
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
9+
10+
class GuzzleWsseExtension extends Extension
11+
{
12+
/**
13+
* @param array $configs
14+
* @param ContainerBuilder $container
15+
*/
16+
public function load(array $configs, ContainerBuilder $container)
17+
{
18+
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
19+
20+
$loader->load('services.xml');
21+
}
22+
}

src/GuzzleBundleWssePlugin.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
namespace Gregurco\Bundle\GuzzleBundleWssePlugin;
4+
5+
6+
use EightPoints\Bundle\GuzzleBundle\EightPointsGuzzleBundlePlugin;
7+
use Gregurco\Bundle\GuzzleBundleWssePlugin\DependencyInjection\GuzzleWsseExtension;
8+
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
9+
use Symfony\Component\HttpKernel\Bundle\Bundle;
10+
use Symfony\Component\DependencyInjection\ContainerBuilder;
11+
use Symfony\Component\DependencyInjection\Definition;
12+
use Symfony\Component\ExpressionLanguage\Expression;
13+
14+
class GuzzleBundleWssePlugin extends Bundle implements EightPointsGuzzleBundlePlugin
15+
{
16+
/**
17+
* @param array $configs
18+
* @param ContainerBuilder $container
19+
*/
20+
public function load(array $configs, ContainerBuilder $container)
21+
{
22+
$extension = new GuzzleWsseExtension();
23+
$extension->load($configs, $container);
24+
}
25+
26+
/**
27+
* @param array $config
28+
* @param ContainerBuilder $container
29+
* @param string $clientName
30+
* @param Definition $handler
31+
*/
32+
public function loadForClient(array $config, ContainerBuilder $container, string $clientName, Definition $handler)
33+
{
34+
if ($config['username'] && $config['password']) {
35+
$wsse = new Definition('%guzzle_bundle_wsse_plugin.middleware.wsse.class%');
36+
$wsse->setArguments([$config['username'], $config['password'], $config['created_at']]);
37+
38+
$wsseServiceName = sprintf('guzzle_bundle_wsse_plugin.middleware.wsse.%s', $clientName);
39+
40+
$container->setDefinition($wsseServiceName, $wsse);
41+
42+
$wsseExpression = new Expression(sprintf('service("%s").attach()', $wsseServiceName));
43+
44+
$handler->addMethodCall('push', [$wsseExpression]);
45+
}
46+
}
47+
48+
/**
49+
* @param ArrayNodeDefinition $pluginNode
50+
*/
51+
public function addConfiguration(ArrayNodeDefinition $pluginNode)
52+
{
53+
$pluginNode
54+
->addDefaultsIfNotSet()
55+
->children()
56+
->scalarNode('username')->defaultNull()->end()
57+
->scalarNode('password')->defaultNull()->end()
58+
->scalarNode('created_at')->defaultNull()->end()
59+
->end();
60+
}
61+
62+
/**
63+
* @return string
64+
*/
65+
public function getPluginName() : string
66+
{
67+
return 'wsse';
68+
}
69+
}

0 commit comments

Comments
 (0)