mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-08-30 03:58:28 +00:00
🚿 additional $file parameter to make the called method aware if a cache file was given
This commit is contained in:
@@ -53,7 +53,7 @@ class QRMarkup extends QROutputAbstract{
|
||||
/**
|
||||
* HTML output
|
||||
*/
|
||||
protected function html():string{
|
||||
protected function html(string $file = null):string{
|
||||
|
||||
$html = empty($this->options->cssClass)
|
||||
? '<div>'
|
||||
@@ -73,7 +73,7 @@ class QRMarkup extends QROutputAbstract{
|
||||
|
||||
$html .= '</div>'.$this->options->eol;
|
||||
|
||||
if($this->options->cachefile){
|
||||
if($file !== null){
|
||||
return '<!DOCTYPE html>'.
|
||||
'<head><meta charset="UTF-8"><title>QR Code</title></head>'.
|
||||
'<body>'.$this->options->eol.$html.'</body>';
|
||||
@@ -87,7 +87,7 @@ class QRMarkup extends QROutputAbstract{
|
||||
*
|
||||
* @see https://github.com/codemasher/php-qrcode/pull/5
|
||||
*/
|
||||
protected function svg():string{
|
||||
protected function svg(string $file = null):string{
|
||||
$matrix = $this->matrix->matrix();
|
||||
|
||||
$svg = sprintf($this->svgHeader, $this->options->cssClass, $this->options->svgViewBoxSize ?? $this->moduleCount)
|
||||
@@ -145,7 +145,7 @@ class QRMarkup extends QROutputAbstract{
|
||||
$svg .= '</svg>'.$this->options->eol;
|
||||
|
||||
// if saving to file, append the correct headers
|
||||
if($this->options->cachefile){
|
||||
if($file !== null){
|
||||
return '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">'.
|
||||
$this->options->eol.$svg;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace chillerlan\QRCode\Output;
|
||||
use chillerlan\QRCode\{Data\QRMatrix, QRCode};
|
||||
use chillerlan\Settings\SettingsContainerInterface;
|
||||
|
||||
use function call_user_func, dirname, file_put_contents, get_called_class, in_array, is_writable, sprintf;
|
||||
use function call_user_func_array, dirname, file_put_contents, get_called_class, in_array, is_writable, sprintf;
|
||||
|
||||
/**
|
||||
* common output abstract
|
||||
@@ -113,10 +113,12 @@ abstract class QROutputAbstract implements QROutputInterface{
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function dump(string $file = null){
|
||||
// call the built-in output method
|
||||
$data = call_user_func([$this, $this->outputMode ?? $this->defaultMode]);
|
||||
$file ??= $this->options->cachefile;
|
||||
|
||||
// call the built-in output method with the optional file path as parameter
|
||||
// to make the called method aware if a cache file was given
|
||||
$data = call_user_func_array([$this, $this->outputMode ?? $this->defaultMode], [$file]);
|
||||
|
||||
if($file !== null){
|
||||
$this->saveToFile($data, $file);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
* @author Smiley <smiley@chillerlan.net>
|
||||
* @copyright 2015 Smiley
|
||||
* @license MIT
|
||||
*
|
||||
* @noinspection PhpUnusedParameterInspection
|
||||
*/
|
||||
|
||||
namespace chillerlan\QRCode\Output;
|
||||
@@ -47,7 +49,7 @@ class QRString extends QROutputAbstract{
|
||||
/**
|
||||
* string output
|
||||
*/
|
||||
protected function text():string{
|
||||
protected function text(string $file = null):string{
|
||||
$str = [];
|
||||
|
||||
foreach($this->matrix->matrix() as $row){
|
||||
@@ -66,7 +68,7 @@ class QRString extends QROutputAbstract{
|
||||
/**
|
||||
* JSON output
|
||||
*/
|
||||
protected function json():string{
|
||||
protected function json(string $file = null):string{
|
||||
return json_encode($this->matrix->matrix());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user