Skip to content

Commit 9c41981

Browse files
committed
:octocat:
1 parent 2f6d079 commit 9c41981

File tree

1 file changed

+52
-32
lines changed

1 file changed

+52
-32
lines changed

README.md

Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# chillerlan/php-qrcode
22

3-
A PHP7 QR Code library based on the [implementation](https://github.com/kazuhikoarase/qrcode-generator) by [Kazuhiko Arase](https://github.com/kazuhikoarase),
3+
A PHP7 QR Code library based on the [implementation](https://github.com/kazuhikoarase/qrcode-generator) by [Kazuhiko Arase](https://github.com/kazuhikoarase),
44
namespaced, cleaned up, improved and other stuff.
55

66
[![Packagist version][packagist-badge]][packagist]
@@ -45,19 +45,19 @@ namespaced, cleaned up, improved and other stuff.
4545
```
4646

4747
#### Manual installation
48-
Download the desired version of the package from [master](https://github.com/chillerlan/php-qrcode/archive/master.zip) or
48+
Download the desired version of the package from [master](https://github.com/chillerlan/php-qrcode/archive/master.zip) or
4949
[release](https://github.com/chillerlan/php-qrcode/releases) and extract the contents to your project folder. After that:
5050
- run `composer install` to install the required dependencies and generate `/vendor/autoload.php`.
51-
- if you use a custom autoloader, point the namespace `chillerlan\QRCode` to the folder `src` of the package
51+
- if you use a custom autoloader, point the namespace `chillerlan\QRCode` to the folder `src` of the package
5252

5353
Profit!
5454

5555
#### Framework Integration
5656
- Drupal
5757
- [Google Authenticator Login `ga_login`](https://www.drupal.org/project/ga_login)
5858
- WordPress
59-
- [Simple 2FA `simple-2fa`](https://wordpress.org/plugins/simple-2fa/)
60-
59+
- [Simple 2FA `simple-2fa`](https://wordpress.org/plugins/simple-2fa/)
60+
6161
#### PHP 5
6262
I've dropped PHP 5 support in early 2017 already. PHP 5.6 and 7.0 will be retired in the end of 2018, so there's no reason to stay on these versions and you really should upgrade your server.
6363
However, if upgrading is not an option for you, you can use the unsupported PHP 5.6 backport of the 2.0 branch. It's available as [`1.0.8` on Packagist](https://packagist.org/packages/chillerlan/php-qrcode#1.0.8). Please let PHP 5 die.
@@ -68,7 +68,7 @@ We want to encode this data into a QRcode image:
6868
// 10 reasons why QR codes are awesome
6969
$data = 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s';
7070

71-
// no, for serious, we want to display a QR code for a mobile authenticator
71+
// no, for serious, we want to display a QR code for a mobile authenticator
7272
$data = 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net';
7373
```
7474

@@ -86,7 +86,7 @@ Wait, what was that? Please again, slower!
8686

8787
### Advanced usage
8888

89-
Ok, step by step. First you'll need a `QRCode` instance, which can be optionally invoked with a `QROptions` object as the only parameter.
89+
Ok, step by step. First you'll need a `QRCode` instance, which can be optionally invoked with a `QROptions` (or a [`ContainerInterface`](https://github.com/chillerlan/php-traits/blob/master/src/ContainerInterface.php), respectively) object as the only parameter.
9090

9191
```php
9292
$options = new QROptions([
@@ -119,7 +119,7 @@ $matrix = $qrcode->getMatrix($data);
119119

120120
foreach($matrix->matrix() as $y => $row){
121121
foreach($row as $x => $module){
122-
122+
123123
// get a module's value
124124
$value = $module;
125125
$value = $matrix->get($x, $y);
@@ -141,7 +141,7 @@ Have a look [in this folder](https://github.com/chillerlan/php-qrcode/tree/maste
141141
#### Custom module values
142142
Previous versions of `QRCode` held only boolean matrix values that only allowed to determine whether a module was dark or not. Now you can distinguish between different parts of the matrix, namely the several required patterns from the QR Code specification, and use them in different ways.
143143

144-
The dark value is the module (light) value shifted by 8 bits to the left: `$value = $M_TYPE << ($bool ? 8 : 0);`, where `$M_TYPE` is one of the `QRMatrix::M_*` constants.
144+
The dark value is the module (light) value shifted by 8 bits to the left: `$value = $M_TYPE << ($bool ? 8 : 0);`, where `$M_TYPE` is one of the `QRMatrix::M_*` constants.
145145
You can check the value for a type explicitly like...
146146
```php
147147
// for true (dark)
@@ -213,12 +213,12 @@ Instead of bloating your code you can simply create your own output interface by
213213

214214
```php
215215
class MyCustomOutput extends QROutputAbstract{
216-
216+
217217
// inherited from QROutputAbstract
218218
protected $matrix; // QRMatrix
219219
protected $moduleCount; // length/width of the matrix
220220
protected $options; // MyCustomOptions or QROptions
221-
221+
222222
// optional constructor
223223
public function __construct(MyCustomOptions $options = null){
224224
$this->options = $options;
@@ -246,28 +246,49 @@ class MyCustomOutput extends QROutputAbstract{
246246
}
247247
```
248248

249-
In case you need additional settings for your output module, just extend `QROptions`.
250-
```php
249+
In case you need additional settings for your output module, just extend `QROptions`...
250+
```
251251
class MyCustomOptions extends QROptions{
252252
protected $myParam = 'defaultValue';
253+
254+
// ...
253255
}
254256
```
257+
...or use the [`ContainerInterface`](https://github.com/chillerlan/php-traits/blob/master/src/ContainerInterface.php), which is the more flexible approach.
255258

256-
You can then call `QRCode` with the custom modules...
257259
```php
258-
$myCustomOptions = new MyCustomOptions([
260+
trait MyCustomOptionsTrait{
261+
protected $myParam = 'defaultValue';
262+
263+
// ...
264+
}
265+
```
266+
set the options:
267+
```php
268+
$myOptions = [
259269
'version' => 5,
260270
'eccLevel' => QRCode::ECC_L,
261271
'outputType' => QRCode::OUTPUT_CUSTOM,
262272
'outputInterface' => MyCustomOutput::class,
263-
// custom settings
273+
// your custom settings
264274
'myParam' => 'whatever value',
265-
]);
275+
];
276+
277+
// extends QROptions
278+
$myCustomOptions = new MyCustomOptions($myOptions);
279+
280+
// using the ContainerInterface
281+
$myCustomOptions = new class($myOptions) extends ContainerAbstract{
282+
use QROptions, MyCustomOptionsTrait;
283+
};
266284

267-
(new QRCode($myCustomOptions))->render($data);
268285
```
269286

270-
...or you can invoke the `QROutputInterface` manually.
287+
You can then call `QRCode` with the custom modules...
288+
```php
289+
(new QRCode($myCustomOptions))->render($data);
290+
```
291+
...or invoke the `QROutputInterface` manually.
271292
```php
272293
$qrOutputInterface = new MyCustomOutput($myCustomOptions, (new QRCode($myCustomOptions))->getMatrix($data));
273294

@@ -276,7 +297,7 @@ $qrOutputInterface->dump();
276297
```
277298

278299
#### Authenticator trait
279-
This library includes a trait for [chillerlan/php-authenticator](https://github.com/chillerlan/php-authenticator) that allows
300+
This library includes a trait for [chillerlan/php-authenticator](https://github.com/chillerlan/php-authenticator) that allows
280301
to create `otpauth://` QR Codes for use with mobile authenticators - just add `"chillerlan/php-authenticator": "^2.0"` to the `require` section of your *composer.json*
281302
```php
282303
use chillerlan\QRCode\{QRCode, QROptions, Traits\QRAuthenticator};
@@ -285,12 +306,12 @@ class MyAuthenticatorClass{
285306
use QRAuthenticator;
286307

287308
public function getQRCode(){
288-
309+
289310
// data fetched from wherever
290311
$this->authenticatorSecret = 'SECRETTEST234567';
291312
$label = 'my label';
292313
$issuer = 'example.com';
293-
314+
294315
// set QROptions options if needed
295316
$this->qrOptions = new QROptions(['outputType' => QRCode::OUTPUT_MARKUP_SVG]);
296317

@@ -303,9 +324,9 @@ class MyAuthenticatorClass{
303324
### API
304325

305326
#### `QRCode` methods
306-
method | return | description
327+
method | return | description
307328
------ | ------ | -----------
308-
`__construct(QROptions $options = null)` | - | -
329+
`__construct(QROptions $options = null)` | - | see [`ContainerInterface`](https://github.com/chillerlan/php-traits/blob/master/src/ContainerInterface.php)
309330
`setOptions(QROptions $options)` | `QRCode` | sets the options, called internally by the constructor
310331
`render(string $data)` | mixed, `QROutputInterface::dump()` | renders a QR Code for the given `$data` and `QROptions`
311332
`getMatrix(string $data)` | `QRMatrix` | returns a `QRMatrix` object for the given `$data` and current `QROptions`
@@ -315,7 +336,7 @@ method | return | description
315336
`isKanji(string $string)` | bool | checks if a string qualifies for `Kanji`
316337

317338
#### `QRCode` constants
318-
name | description
339+
name | description
319340
---- | -----------
320341
`VERSION_AUTO` | `QROptions::$version`
321342
`MASK_PATTERN_AUTO` | `QROptions::$maskPattern`
@@ -352,24 +373,23 @@ property | type | default | allowed | description
352373
`$moduleValues` | array | array | array | Module values map, see [Custom output modules](#custom-qroutputinterface)
353374

354375
#### `QRAuthenticator` trait methods
355-
method | return | description
376+
method | return | description
356377
------ | ------ | -----------
357378
`getURIQRCode(string $label, string $issuer)` | `QRCode::render()` | protected
358379
`getAuthenticator()` | `Authenticator` | protected, returns an `Authenticator` object with the given settings
359380

360381
#### `QRAuthenticator` trait properties
361-
362382
property | type | default | allowed | description
363383
-------- | ---- | ------- | ------- | -----------
364384
`$qrOptions` | `QROptions` | - | - | a `QROptions` object for internal use
365385
`$authenticatorSecret` | string | - | * | the secret phrase to use for the QR Code
366-
`$authenticatorDigits` | int | 6 | 6...8 |
367-
`$authenticatorPeriod` | int | 30 | 10...60 |
368-
`$authenticatorMode` | string | `totp` | `totp`, `hotp` |
369-
`$authenticatorAlgo` | string | `SHA1` | `SHA1`, `SHA256`, `SHA512` |
386+
`$authenticatorDigits` | int | 6 | 6...8 |
387+
`$authenticatorPeriod` | int | 30 | 10...60 |
388+
`$authenticatorMode` | string | `totp` | `totp`, `hotp` |
389+
`$authenticatorAlgo` | string | `SHA1` | `SHA1`, `SHA256`, `SHA512` |
370390

371391
#### `QRMatrix` methods
372-
method | return | description
392+
method | return | description
373393
------ | ------ | -----------
374394
`__construct(int $version, int $eclevel)` | - | -
375395
`matrix()` | array | the internal matrix representation as a 2 dimensional array

0 commit comments

Comments
 (0)