Skip to content

Commit 17575b9

Browse files
authored
Merge pull request #11 from DragonBe/psr-compat
Psr compat
2 parents 5becf6b + 7ca6577 commit 17575b9

11 files changed

Lines changed: 452 additions & 39 deletions

File tree

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,4 @@ jobs:
7777

7878
- run:
7979
name: Execute mutation testing
80-
command: ./vendor/bin/infection --configuration=infection.json.dist --coverage=build/logs/coverage
80+
command: ./vendor/bin/infection --configuration=infection.json.dist --coverage=build/logs/coverage --only-covered

composer.json

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
"type": "library",
55
"require": {
66
"php": ">= 7.2",
7-
"guzzlehttp/guzzle": "^6.3"
7+
"guzzlehttp/guzzle": "^6.3",
8+
"psr/http-message": "^1.0",
9+
"psr/http-client": "^1.0",
10+
"ricardofiorani/guzzle-psr18-adapter": "^1.0",
11+
"psr/http-factory": "^1.0"
812
},
913
"autoload": {
1014
"psr-4": {
@@ -28,5 +32,17 @@
2832
"email": "dragonbe+github@gmail.com"
2933
}
3034
],
31-
"minimum-stability": "stable"
35+
"minimum-stability": "stable",
36+
"scripts": {
37+
"check": [
38+
"@cs-check",
39+
"@test",
40+
"@infection"
41+
],
42+
"cs-check": "phpcs",
43+
"cs-fix": "phpcbf",
44+
"test": "phpunit --colors=always",
45+
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml",
46+
"infection": "infection --only-covered"
47+
}
3248
}

composer.lock

Lines changed: 159 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/hibp-count.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
11
<?php
22

3-
require_once __DIR__ . '/vendor/autoload.php';
3+
namespace Hibp;
4+
5+
use Dragonbe\Hibp\Hibp;
6+
use Dragonbe\Hibp\HibpFactory;
7+
8+
require_once __DIR__ . '/../vendor/autoload.php';
9+
10+
/*
11+
* This example shows how you can validate multiple passwords
12+
* to the Have I been pwned API service.
13+
*
14+
* It also shows how you can retrieve the amount of times a
15+
* given password was found in breaches.
16+
*/
17+
18+
/**
19+
* @var Hibp
20+
*/
21+
$hibp = HibpFactory::create();
422

5-
$hibp = \Dragonbe\Hibp\HibpFactory::create();
623
$passwords = ['password', 'NVt3MpvQ'];
724
foreach ($passwords as $password) {
825
$found = $hibp->isPwnedPassword($password);

examples/hibp-psr18.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace Hibp;
4+
5+
use Dragonbe\Hibp\Hibp;
6+
use Dragonbe\Hibp\HibpFactory;
7+
use GuzzleHttp\Psr7\Request;
8+
use GuzzleHttp\Psr7\Response;
9+
use Psr\Http\Client\ClientInterface;
10+
use Psr\Http\Message\RequestInterface;
11+
use Psr\Http\Message\ResponseInterface;
12+
use RicardoFiorani\GuzzlePsr18Adapter\Client;
13+
14+
require_once __DIR__ . '/../vendor/autoload.php';
15+
16+
/*
17+
* This example shows the usage of a PSR18 compliant
18+
* HTTP class to make a call to the Have I been pwned
19+
* API service.
20+
*
21+
* @see https://www.php-fig.org/psr/psr-18/
22+
*/
23+
/**
24+
* @var ClientInterface
25+
*/
26+
$client = new Client(HibpFactory::createConfig());
27+
28+
/**
29+
* @var RequestInterface
30+
*/
31+
$request = new Request('GET', '/');
32+
33+
/**
34+
* @var ResponseInterface
35+
*/
36+
$response = new Response();
37+
38+
/**
39+
* @var Hibp
40+
*/
41+
$hibp = new Hibp($client, $request, $response);
42+
43+
echo 'Password "password": ' . ($hibp->isPwnedPassword('password') ? 'Pwned' : 'OK') . PHP_EOL;
44+
echo 'Password "NVt3MpvQ": ' . ($hibp->isPwnedPassword('NVt3MpvQ') ? 'Pwned' : 'OK') . PHP_EOL;

examples/hibp.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
<?php
22

3+
namespace Hibp;
4+
5+
use Dragonbe\Hibp\Hibp;
6+
use Dragonbe\Hibp\HibpFactory;
7+
38
require_once __DIR__ . '/vendor/autoload.php';
49

5-
$hibp = \Dragonbe\Hibp\HibpFactory::create();
10+
/*
11+
* This example shows how to quickly get started
12+
* to make a call to the Have I been pwned API service.
13+
*/
14+
15+
/**
16+
* @var Hibp
17+
*/
18+
$hibp = HibpFactory::create();
19+
620
echo 'Password "password": ' . ($hibp->isPwnedPassword('password') ? 'Pwned' : 'OK') . PHP_EOL;
721
echo 'Password "NVt3MpvQ": ' . ($hibp->isPwnedPassword('NVt3MpvQ') ? 'Pwned' : 'OK') . PHP_EOL;
822

0 commit comments

Comments
 (0)