Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit 3095cd3

Browse files
DragonBeweierophinney
authored andcommitted
Providing a working example documentation
To make it simple for users to make use of this validation feature, I created a working example people can use.
1 parent c709e51 commit 3095cd3

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

doc/book/validators/undisclosed-password.md

+50
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,53 @@ $result = $validator->isValid('8aDk=XiW2E.77tLfuAcB');
3636
// $result is TRUE because "8aDk=XiW2E.77tLfuAcB" was not found in a data breach
3737
```
3838
39+
## A simple command line example
40+
41+
In this example I'm using `zendframework/zend-diactoros` for HTTP messaging and `php-http/curl-client` as the HTTP client. Let's begin with installation of all required packages:
42+
43+
```bash
44+
$ composer require \
45+
php-http/message \
46+
php-http/message-factory \
47+
php-http/discovery \
48+
php-http/curl-client \
49+
zendframework/zend-diactoros \
50+
zendframework/zend-validator
51+
```
52+
53+
Next thing is I create a file `undisclosed.php` where I will put in my code.
54+
55+
```php
56+
<?php
57+
58+
namespace Undisclosed;
59+
60+
use Http\Client\Curl\Client;
61+
use Zend\Diactoros\RequestFactory;
62+
use Zend\Diactoros\ResponseFactory;
63+
use Zend\Validator\UndisclosedPassword;
64+
65+
require_once __DIR__ . '/vendor/autoload.php';
66+
67+
68+
$requestFactory = new RequestFactory();
69+
$responseFactory = new ResponseFactory();
70+
$client = new Client($responseFactory, null);
71+
72+
$undisclosedPassword = new UndisclosedPassword($client, $requestFactory, $responseFactory);
73+
echo 'Password "password" is ' . ($undisclosedPassword->isValid('password') ? 'not disclosed' : 'disclosed') . PHP_EOL;
74+
echo 'Password "NVt3MpvQ" is ' . ($undisclosedPassword->isValid('NVt3MpvQ') ? 'not disclosed' : 'disclosed') . PHP_EOL;
75+
```
76+
77+
To run it, I use PHP on the command line:
78+
79+
```bash
80+
$ php undisclosed.php
81+
```
82+
83+
And it will give me the following output:
84+
85+
```bash
86+
Password "password" is disclosed
87+
Password "NVt3MpvQ" is not disclosed
88+
```

0 commit comments

Comments
 (0)