You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+52-32Lines changed: 52 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# chillerlan/php-qrcode
2
2
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),
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.
63
63
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:
@@ -86,7 +86,7 @@ Wait, what was that? Please again, slower!
86
86
87
87
### Advanced usage
88
88
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.
@@ -141,7 +141,7 @@ Have a look [in this folder](https://github.com/chillerlan/php-qrcode/tree/maste
141
141
#### Custom module values
142
142
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.
143
143
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.
145
145
You can check the value for a type explicitly like...
146
146
```php
147
147
// for true (dark)
@@ -213,12 +213,12 @@ Instead of bloating your code you can simply create your own output interface by
213
213
214
214
```php
215
215
class MyCustomOutput extends QROutputAbstract{
216
-
216
+
217
217
// inherited from QROutputAbstract
218
218
protected $matrix; // QRMatrix
219
219
protected $moduleCount; // length/width of the matrix
220
220
protected $options; // MyCustomOptions or QROptions
221
-
221
+
222
222
// optional constructor
223
223
public function __construct(MyCustomOptions $options = null){
224
224
$this->options = $options;
@@ -246,28 +246,49 @@ class MyCustomOutput extends QROutputAbstract{
246
246
}
247
247
```
248
248
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
+
```
251
251
class MyCustomOptions extends QROptions{
252
252
protected $myParam = 'defaultValue';
253
+
254
+
// ...
253
255
}
254
256
```
257
+
...or use the [`ContainerInterface`](https://github.com/chillerlan/php-traits/blob/master/src/ContainerInterface.php), which is the more flexible approach.
255
258
256
-
You can then call `QRCode` with the custom modules...
257
259
```php
258
-
$myCustomOptions = new MyCustomOptions([
260
+
trait MyCustomOptionsTrait{
261
+
protected $myParam = 'defaultValue';
262
+
263
+
// ...
264
+
}
265
+
```
266
+
set the options:
267
+
```php
268
+
$myOptions = [
259
269
'version' => 5,
260
270
'eccLevel' => QRCode::ECC_L,
261
271
'outputType' => QRCode::OUTPUT_CUSTOM,
262
272
'outputInterface' => MyCustomOutput::class,
263
-
// custom settings
273
+
// your custom settings
264
274
'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
+
};
266
284
267
-
(new QRCode($myCustomOptions))->render($data);
268
285
```
269
286
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.
271
292
```php
272
293
$qrOutputInterface = new MyCustomOutput($myCustomOptions, (new QRCode($myCustomOptions))->getMatrix($data));
273
294
@@ -276,7 +297,7 @@ $qrOutputInterface->dump();
276
297
```
277
298
278
299
#### 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
280
301
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*
281
302
```php
282
303
use chillerlan\QRCode\{QRCode, QROptions, Traits\QRAuthenticator};
@@ -285,12 +306,12 @@ class MyAuthenticatorClass{
285
306
use QRAuthenticator;
286
307
287
308
public function getQRCode(){
288
-
309
+
289
310
// data fetched from wherever
290
311
$this->authenticatorSecret = 'SECRETTEST234567';
291
312
$label = 'my label';
292
313
$issuer = 'example.com';
293
-
314
+
294
315
// set QROptions options if needed
295
316
$this->qrOptions = new QROptions(['outputType' => QRCode::OUTPUT_MARKUP_SVG]);
296
317
@@ -303,9 +324,9 @@ class MyAuthenticatorClass{
303
324
### API
304
325
305
326
#### `QRCode` methods
306
-
method | return | description
327
+
method | return | description
307
328
------ | ------ | -----------
308
-
`__construct(QROptions $options = null)` | - | -
329
+
`__construct(QROptions $options = null)` | - | see [`ContainerInterface`](https://github.com/chillerlan/php-traits/blob/master/src/ContainerInterface.php)
309
330
`setOptions(QROptions $options)` | `QRCode` | sets the options, called internally by the constructor
310
331
`render(string $data)` | mixed, `QROutputInterface::dump()` | renders a QR Code for the given `$data` and `QROptions`
311
332
`getMatrix(string $data)` | `QRMatrix` | returns a `QRMatrix` object for the given `$data` and current `QROptions`
@@ -315,7 +336,7 @@ method | return | description
315
336
`isKanji(string $string)` | bool | checks if a string qualifies for `Kanji`
0 commit comments