Skip to content

Commit ff1c4b5

Browse files
author
Harry Bragg
authored
Guzzle -> v6 [PLA-389] (#21)
* upgrade to guzzle v6 instead of v5 * remove support for php5.5, because * fix some code styling stuff * some comprehisilbity fixes * code readability * update build image to use php7-phpdbg, 100% coverage * actually add the query parameters into the url
1 parent 8e987d7 commit ff1c4b5

36 files changed

+1180
-1360
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
language: php
22

33
php:
4-
- 5.5
54
- 5.6
65
- 7.0
76
- hhvm

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

33
All Notable changes to `gigya-client` will be documented in this file
44

5+
## 1.0 - 2016-11-28
6+
7+
### Changed
8+
- Upgrade Guzzle from v5 to v6
9+
- All Subscribers are now Guzzle Middleware
10+
- Renamed `->addSubscriber` to `->addHandler`
11+
- Renamed `->removeSubscriber` to `->removeHandler`
12+
13+
## 0.3 - 2016-04-02
14+
15+
### Added
16+
- OAuth2 authentication
17+
518
## 0.2 - 2015-10-20
619

720
### Changed

Dockerfile

Lines changed: 0 additions & 10 deletions
This file was deleted.

Makefile

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
SHELL = /bin/sh
22

33
DOCKER ?= $(shell which docker)
4-
DOCKER_REPOSITORY := graze/gigya-client
4+
DOCKER_REPOSITORY := graze/php-alpine
55
VOLUME := /srv
66
VOLUME_MAP := -v $$(pwd):${VOLUME}
77
DOCKER_RUN_BASE := ${DOCKER} run --rm -t ${VOLUME_MAP} -w ${VOLUME}
8-
DOCKER_RUN := ${DOCKER_RUN_BASE} ${DOCKER_REPOSITORY}:latest
8+
DOCKER_RUN := ${DOCKER_RUN_BASE} ${DOCKER_REPOSITORY}:test
99

1010
.PHONY: install composer clean help
1111
.PHONY: test lint lint-fix test-unit test-integration test-matrix test-coverage test-coverage-html test-coverage-clover
@@ -16,14 +16,13 @@ DOCKER_RUN := ${DOCKER_RUN_BASE} ${DOCKER_REPOSITORY}:latest
1616

1717
install: ## Download the dependencies then build the image :rocket:.
1818
make 'composer-install --optimize-autoloader --ignore-platform-reqs'
19-
$(DOCKER) build --tag ${DOCKER_REPOSITORY}:latest .
2019

2120
composer-%: ## Run a composer command, `make "composer-<command> [...]"`.
2221
${DOCKER} run -t --rm \
23-
-v $$(pwd):/usr/src/app \
22+
-v $$(pwd):/app \
2423
-v ~/.composer:/root/composer \
2524
-v ~/.ssh:/root/.ssh:ro \
26-
graze/composer --ansi --no-interaction $* $(filter-out $@,$(MAKECMDGOALS))
25+
composer/composer:alpine --ansi --no-interaction $* $(filter-out $@,$(MAKECMDGOALS))
2726

2827
clean: ## Clean up any images.
2928
$(DOCKER) rmi ${DOCKER_REPOSITORY}:latest
@@ -54,13 +53,13 @@ test-performance: ## Run the performance testsuite.
5453
$(DOCKER_RUN) vendor/bin/phpunit --colors=always --testsuite performance
5554

5655
test-coverage: ## Run all tests and output coverage to the console.
57-
$(DOCKER_RUN) vendor/bin/phpunit --coverage-text --testsuite coverage
56+
$(DOCKER_RUN) phpdbg7 -qrr vendor/bin/phpunit --coverage-text --testsuite coverage
5857

5958
test-coverage-html: ## Run all tests and output html results
60-
$(DOCKER_RUN) vendor/bin/phpunit --coverage-html ./tests/report/html --testsuite coverage
59+
$(DOCKER_RUN) phpdbg7 -qrr vendor/bin/phpunit --coverage-html ./tests/report/html --testsuite coverage
6160

6261
test-coverage-clover: ## Run all tests and output clover coverage to file.
63-
$(DOCKER_RUN) vendor/bin/phpunit --coverage-clover=./tests/report/coverage.clover --testsuite coverage
62+
$(DOCKER_RUN) phpdbg7 -qrr vendor/bin/phpunit --coverage-clover=./tests/report/coverage.clover --testsuite coverage
6463

6564

6665
# Help

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ $account = $response->getData();
4747
```php
4848
$grant = new ManualGrant();
4949
$gigya = new Gigya($key, $secret, $region, null, ['auth' => 'oauth2-custom']);
50-
$gigya->addSubscriber(new OAuth2Subscriber($grant));
50+
$gigya->addHandler(OAuth2Subscriber::middleware($grant));
5151

5252
$tokenResponse = $gigya->socialize()->getToken([
5353
'grant_type' => 'code',

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
],
2323
"require": {
2424
"php": ">=5.5.0",
25-
"guzzlehttp/guzzle": "^5.3",
25+
"guzzlehttp/guzzle": "^6.2",
2626
"illuminate/support": "^5.0",
2727
"graze/standards": "^1.0"
2828
},
2929
"require-dev": {
30-
"phpunit/phpunit" : "^4",
30+
"phpunit/phpunit" : "^5",
3131
"mockery/mockery": "^0.9.4",
3232
"squizlabs/php_codesniffer": "^2.3"
3333
},

src/Auth/CredentialsAuth.php

Lines changed: 0 additions & 99 deletions
This file was deleted.
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
/**
3+
* This file is part of graze/gigya-client
4+
*
5+
* Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*
10+
* @license https://github.com/graze/gigya-client/blob/master/LICENSE.md
11+
* @link https://github.com/graze/gigya-client
12+
*/
13+
14+
namespace Graze\Gigya\Auth;
15+
16+
use Closure;
17+
use GuzzleHttp\Psr7\Uri;
18+
use Psr\Http\Message\RequestInterface;
19+
use Psr\Http\Message\ResponseInterface as GuzzleResponseInterface;
20+
21+
class CredentialsAuthMiddleware
22+
{
23+
const AUTH_NAME = 'credentials';
24+
25+
/**
26+
* @var string
27+
*/
28+
private $apiKey;
29+
30+
/**
31+
* @var string
32+
*/
33+
private $secret;
34+
35+
/**
36+
* @var null|string
37+
*/
38+
private $userKey;
39+
/**
40+
* @var callable
41+
*/
42+
private $nextHandler;
43+
44+
/**
45+
* @param callable $nextHandler
46+
* @param string $apiKey
47+
* @param string $secret
48+
* @param string|null $userKey
49+
*/
50+
public function __construct(callable $nextHandler, $apiKey, $secret, $userKey = null)
51+
{
52+
$this->nextHandler = $nextHandler;
53+
$this->apiKey = $apiKey;
54+
$this->secret = $secret;
55+
$this->userKey = $userKey;
56+
}
57+
58+
/**
59+
* Inject credentials information into the query parameters
60+
*
61+
* @param RequestInterface $request
62+
* @param array $options
63+
*
64+
* @return GuzzleResponseInterface
65+
*/
66+
public function __invoke(RequestInterface $request, array $options)
67+
{
68+
if ($request->getUri()->getScheme() == 'https' && $options['auth'] == static::AUTH_NAME) {
69+
$uri = Uri::withQueryValue($request->getUri(), 'client_id', $this->userKey ?: $this->apiKey);
70+
$uri = Uri::withQueryValue($uri, 'client_secret', $this->secret);
71+
$request = $request->withUri($uri);
72+
}
73+
$fn = $this->nextHandler;
74+
return $fn($request, $options);
75+
}
76+
77+
/**
78+
* @return string
79+
*/
80+
public function getApiKey()
81+
{
82+
return $this->apiKey;
83+
}
84+
85+
/**
86+
* @return string
87+
*/
88+
public function getSecret()
89+
{
90+
return $this->secret;
91+
}
92+
93+
/**
94+
* @return string|null
95+
*/
96+
public function getUserKey()
97+
{
98+
return $this->userKey;
99+
}
100+
101+
/**
102+
* Return a middleware handler function for this Authentication
103+
*
104+
* @param string $apiKey
105+
* @param string $secret
106+
* @param string|null $userKey
107+
*
108+
* @return Closure
109+
*/
110+
public static function middleware($apiKey, $secret, $userKey = null)
111+
{
112+
return function (callable $handler) use ($apiKey, $secret, $userKey) {
113+
return new static($handler, $apiKey, $secret, $userKey);
114+
};
115+
}
116+
}

0 commit comments

Comments
 (0)