Skip to content

Commit 9c897be

Browse files
committed
📖
1 parent 7448525 commit 9c897be

File tree

12 files changed

+44
-62
lines changed

12 files changed

+44
-62
lines changed

docs/Appendix/Contribute.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Please don't just write "headline says all" because the reply will likely be sim
1414

1515
So you found a bug or the library code is somehow misbehaving? That's great (well, not that great tho). In that case,
1616
please [open a bug report and FILL OUT THE ISSUE TEMPLATE](https://github.com/chillerlan/php-qrcode/issues/new?assignees=&labels=bug&projects=&template=bug_report.md&title=%5BBUG%5D)
17-
(i have to write that in all caps because nobody actually does it which usually leads to several avoidable follow-up questions that cost both of us precious time).
17+
(I have to write that in all caps because nobody actually does it which usually leads to several avoidable follow-up questions that cost both of us precious time).
1818
Below an example of the bug report template (it's not that hard):
1919

2020
**Describe the bug**

docs/Appendix/URI-Content.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,11 @@ END:VCALENDAR
253253

254254
## Credit Transfer
255255

256-
### SEPA
256+
### SEPA (European Payments Council)
257257
- [Guidelines to Enable the Data Capture for the Initiation of a SEPA Credit Transfer](https://www.europeanpaymentscouncil.eu/document-library/guidance-documents/quick-response-code-guidelines-enable-data-capture-initiation)
258258
- [sepa-qr-data library for PHP (GitHub)](https://github.com/smhg/sepa-qr-data-php)
259259

260-
### Pix
260+
### Pix (Banco Central do Brasil)
261261
- [Manual de Padrões para Iniciação do Pix (PDF)](https://www.bcb.gov.br/content/estabilidadefinanceira/pix/Regulamento_Pix/II_ManualdePadroesparaIniciacaodoPix.pdf)
262262
- [OpenBoleto (GitHub)](https://github.com/openboleto/openboleto)
263263

docs/Built-In-Output/QREps.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ exit;
6060
| (protected) `module(int $x, int $y, int $M_TYPE)` | `string` | Returns a path segment for a single module |
6161

6262

63-
## Options that affect this module
63+
## Options that affect this class
6464

6565
| property | type |
6666
|-----------------------|---------|

docs/Built-In-Output/QRFpdf.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ echo $fpdf->Output('S');
6565
| (protected) `module(int $x, int $y, int $M_TYPE)` | `void` | Renders a single module |
6666

6767

68-
## Options that affect this module
68+
## Options that affect this class
6969

7070
| property | type |
7171
|---------------------|----------|

docs/Built-In-Output/QRGdImage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ imagedestroy($gdImage);
8484
| (abstract protected) `renderImage()` | `void` | Renders the image with the gdimage function for the desired output, implemented by child classes |
8585

8686

87-
## Options that affect this module
87+
## Options that affect this class
8888

8989
| property | type |
9090
|------------------------|----------------|

docs/Built-In-Output/QRImagick.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ echo $imagick->getImageBlob();
8686
| (protected) `setTransparencyColor()` | `void` | Sets the transparency color |
8787

8888

89-
## Options that affect this module
89+
## Options that affect this class
9090

9191
| property | type |
9292
|------------------------|----------|

docs/Built-In-Output/QRInterventionImage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ $out = $qrOutputInterface->dump();
8686
| (protected) `module()` | `void` | Draws a single pixel at the given position |
8787

8888

89-
## Options that affect this module
89+
## Options that affect this class
9090

9191
| property | type |
9292
|------------------------|----------|

docs/Built-In-Output/QRMarkupHTML.md

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -79,26 +79,9 @@ header('Content-type: text/html');
7979
| (protected) `getCssClass(int $M_TYPE = 0)` | `string` | Returns a string with all css classes for the current element |
8080

8181

82-
## Options that affect this module
82+
## Options that affect this class
8383

8484
| property | type |
8585
|----------------|----------|
8686
| `$cssClass` | `string` |
8787
| `$eol` | `string` |
88-
89-
90-
### Options that have no effect
91-
92-
| property | reason |
93-
|------------------------|---------|
94-
| `$bgColor` | via CSS |
95-
| `$circleRadius` | N/A |
96-
| `$connectPaths` | N/A |
97-
| `$drawCircularModules` | N/A |
98-
| `$drawLightModules` | N/A |
99-
| `$excludeFromConnect` | N/A |
100-
| `$imageTransparent` | N/A |
101-
| `$keepAsSquare` | N/A |
102-
| `$outputBase64` | N/A |
103-
| `$returnResource` | N/A |
104-
| `$scale` | via CSS |

docs/Customizing/Custom-output-interface.md

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -89,46 +89,35 @@ In order to do so, we need to collect the modules per `$M_TYPE` before we can re
8989
}
9090
```
9191

92-
We've introduced another method that handles the module rendering, which incooperates handling of the `QROptions::$drawLightModules` setting:
93-
94-
```php
95-
protected function module(int $x, int $y, int $M_TYPE):string{
96-
97-
if(!$this->drawLightModules && !$this->matrix->isDark($M_TYPE)){
98-
return '';
99-
}
100-
101-
return sprintf('x: %s, y: %s', $x, $y);
102-
}
103-
```
104-
10592
Speaking of option settings, there's also `QROptions::$connectPaths` which we haven't taken care of yet - the good news is that we don't need to as it is already implemented!
10693
We'll modify the above `dump()` method to use `QROutputAbstract::collectModules()` instead.
10794

108-
The module collector accepts a `Closure` as its only parameter, which is called with 4 parameters:
95+
The module collector calls a method `moduleTransform()` internally, which is called with 4 parameters:
10996

11097
- `$x` : current column
11198
- `$y` : current row
11299
- `$M_TYPE` : field value
113100
- `$M_TYPE_LAYER`: (possibly modified) field value that acts as layer id
114101

115-
We only need the first 3 parameters, so our closure would look as follows:
102+
We'## introduce another method that handles the module rendering, which incooperates handling of the `QROptions::$drawLightModules` setting:
116103

117104
```php
118-
$closure = fn(int $x, int $y, int $M_TYPE):string => $this->module($x, $y, $M_TYPE);
119-
```
105+
protected function moduleTransform(int $x, int $y, int $M_TYPE, int $M_TYPE_LAYER):string{
120106

121-
As of PHP 8.1+ we can narrow this down with the [first class callable syntax](https://www.php.net/manual/en/functions.first_class_callable_syntax.php):
107+
if(!$this->drawLightModules && !$this->matrix->isDark($M_TYPE)){
108+
return '';
109+
}
122110

123-
```php
124-
$closure = $this->module(...);
111+
return sprintf('x: %s, y: %s', $x, $y);
112+
}
125113
```
126114

115+
127116
This is our final output method then:
128117

129118
```php
130119
public function dump(string $file = null):string{
131-
$collections = $this->collectModules($this->module(...));
120+
$collections = $this->collectModules();
132121

133122
// build the final output
134123
$out = [];
@@ -151,8 +140,7 @@ This is our final output method then:
151140
To run the output we just need to set the `QROptions::$outputInterface` to our custom class:
152141

153142
```php
154-
$options = new QROptions;
155-
$options->outputType = QROutputInterface::CUSTOM;
143+
$options = new QROptions;
156144
$options->outputInterface = MyCustomOutput::class;
157145
$options->connectPaths = true;
158146
$options->drawLightModules = true;
@@ -169,7 +157,20 @@ $qrcode->addByteSegment('test');
169157
var_dump($qrcode->render());
170158
```
171159

160+
Alternatively, you can invoke the `QROutputInterface` manually:
161+
162+
```php
163+
$qrcode = new QRCode($options);
164+
$qrOutputInterface = new MyCustomOutput($options, $qrcode->getMatrix($data));
165+
166+
//dump the output, which is equivalent to QRCode::render()
167+
$qrOutputInterface->dump();
168+
// render to file
169+
$qrOutputInterface->dump('/path/to/qrcode.svg');
170+
```
171+
172172
The output looks similar to the following:
173+
173174
```
174175
these-modules-are-light (000000000010)
175176
@@ -227,7 +228,7 @@ class MyCustomOutput extends QROutputAbstract{
227228
return implode("\n", $out);
228229
}
229230

230-
protected function module(int $x, int $y, int $M_TYPE):string{
231+
protected function moduleTransform(int $x, int $y, int $M_TYPE, int $M_TYPE_LAYER):string{
231232

232233
if(!$this->drawLightModules && !$this->matrix->isDark($M_TYPE)){
233234
return '';

docs/Customizing/QROutputAbstract.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ class MyOutput extends QROutputAbstract{
117117

118118
Both methods return a module value, the main difference is that `getModuleValueAt()` is a convenience method
119119
that makes an extra call to retrieve the `$M_TYPE` from the given matrix coordinate to return the value via `getModuleValue()`.
120-
121120
A `foreach` loop over the matrix gives you the key (coordinate) *and* value of an array element:
122121

123122
```php
@@ -222,6 +221,7 @@ class MyOutput extends QROutputAbstract{
222221
return implode($this->options->eol, $paths);
223222
}
224223

224+
// this method must be implemented/overridden if your output class uses the module collector
225225
protected function moduleTransform(int $x, int $y, int $M_TYPE, int $M_TYPE_LAYER):string{
226226
return sprintf('%d %d %012b', $x, $y, $M_TYPE);
227227
}
@@ -235,11 +235,8 @@ Sometimes it can be necessary to override `collectModules()` in order to apply s
235235
### `saveToFile()` and `toBase64DataURI()`
236236

237237
The void method `saveToFile()` takes a data blob and the `$file` given in `QROutputInterface::dump()` and save to the path if it is not `null` - the file path itself is not checked except for writability.
238-
239238
The final output can be transformed to a [base64 data URI](https://en.wikipedia.org/wiki/Data_URI_scheme) with `toBase64DataURI()`, where the data blob and a valid mime type as parameters - the mime type is not checked.
240239

241-
242-
243240
```php
244241
class MyOutput extends QROutputAbstract{
245242

0 commit comments

Comments
 (0)