Skip to content

Commit

Permalink
Merge pull request #11 from DragonBe/psr-compat
Browse files Browse the repository at this point in the history
Psr compat
  • Loading branch information
DragonBe authored Apr 7, 2019
2 parents 5becf6b + 7ca6577 commit 17575b9
Show file tree
Hide file tree
Showing 11 changed files with 452 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ jobs:

- run:
name: Execute mutation testing
command: ./vendor/bin/infection --configuration=infection.json.dist --coverage=build/logs/coverage
command: ./vendor/bin/infection --configuration=infection.json.dist --coverage=build/logs/coverage --only-covered
20 changes: 18 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
"type": "library",
"require": {
"php": ">= 7.2",
"guzzlehttp/guzzle": "^6.3"
"guzzlehttp/guzzle": "^6.3",
"psr/http-message": "^1.0",
"psr/http-client": "^1.0",
"ricardofiorani/guzzle-psr18-adapter": "^1.0",
"psr/http-factory": "^1.0"
},
"autoload": {
"psr-4": {
Expand All @@ -28,5 +32,17 @@
"email": "[email protected]"
}
],
"minimum-stability": "stable"
"minimum-stability": "stable",
"scripts": {
"check": [
"@cs-check",
"@test",
"@infection"
],
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"test": "phpunit --colors=always",
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml",
"infection": "infection --only-covered"
}
}
160 changes: 159 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 19 additions & 2 deletions examples/hibp-count.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
<?php

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

use Dragonbe\Hibp\Hibp;
use Dragonbe\Hibp\HibpFactory;

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

/*
* This example shows how you can validate multiple passwords
* to the Have I been pwned API service.
*
* It also shows how you can retrieve the amount of times a
* given password was found in breaches.
*/

/**
* @var Hibp
*/
$hibp = HibpFactory::create();

$hibp = \Dragonbe\Hibp\HibpFactory::create();
$passwords = ['password', 'NVt3MpvQ'];
foreach ($passwords as $password) {
$found = $hibp->isPwnedPassword($password);
Expand Down
44 changes: 44 additions & 0 deletions examples/hibp-psr18.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Hibp;

use Dragonbe\Hibp\Hibp;
use Dragonbe\Hibp\HibpFactory;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use RicardoFiorani\GuzzlePsr18Adapter\Client;

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

/*
* This example shows the usage of a PSR18 compliant
* HTTP class to make a call to the Have I been pwned
* API service.
*
* @see https://www.php-fig.org/psr/psr-18/
*/
/**
* @var ClientInterface
*/
$client = new Client(HibpFactory::createConfig());

/**
* @var RequestInterface
*/
$request = new Request('GET', '/');

/**
* @var ResponseInterface
*/
$response = new Response();

/**
* @var Hibp
*/
$hibp = new Hibp($client, $request, $response);

echo 'Password "password": ' . ($hibp->isPwnedPassword('password') ? 'Pwned' : 'OK') . PHP_EOL;
echo 'Password "NVt3MpvQ": ' . ($hibp->isPwnedPassword('NVt3MpvQ') ? 'Pwned' : 'OK') . PHP_EOL;
16 changes: 15 additions & 1 deletion examples/hibp.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
<?php

namespace Hibp;

use Dragonbe\Hibp\Hibp;
use Dragonbe\Hibp\HibpFactory;

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

$hibp = \Dragonbe\Hibp\HibpFactory::create();
/*
* This example shows how to quickly get started
* to make a call to the Have I been pwned API service.
*/

/**
* @var Hibp
*/
$hibp = HibpFactory::create();

echo 'Password "password": ' . ($hibp->isPwnedPassword('password') ? 'Pwned' : 'OK') . PHP_EOL;
echo 'Password "NVt3MpvQ": ' . ($hibp->isPwnedPassword('NVt3MpvQ') ? 'Pwned' : 'OK') . PHP_EOL;

Loading

0 comments on commit 17575b9

Please sign in to comment.