diff options
author | Mario <mario@mariovavti.com> | 2023-03-19 13:55:18 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2023-03-19 13:55:18 +0000 |
commit | 89285f1408d21091bb80d45b391ddcbe06ba8d0f (patch) | |
tree | b2eb07d9f3d91d77f89a4565a58e6e5231b20c1c /vendor/chillerlan/php-qrcode/src/Output/QROutputAbstract.php | |
parent | 0a679e503ef367eda3085c44af103ee53869a94f (diff) | |
parent | 17c0bb2069dcfe35d3febc5bfdb3a7295f15d49c (diff) | |
download | volse-hubzilla-89285f1408d21091bb80d45b391ddcbe06ba8d0f.tar.gz volse-hubzilla-89285f1408d21091bb80d45b391ddcbe06ba8d0f.tar.bz2 volse-hubzilla-89285f1408d21091bb80d45b391ddcbe06ba8d0f.zip |
Merge branch '8.2RC'8.2
Diffstat (limited to 'vendor/chillerlan/php-qrcode/src/Output/QROutputAbstract.php')
-rw-r--r-- | vendor/chillerlan/php-qrcode/src/Output/QROutputAbstract.php | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/vendor/chillerlan/php-qrcode/src/Output/QROutputAbstract.php b/vendor/chillerlan/php-qrcode/src/Output/QROutputAbstract.php new file mode 100644 index 000000000..d4ed3d0c9 --- /dev/null +++ b/vendor/chillerlan/php-qrcode/src/Output/QROutputAbstract.php @@ -0,0 +1,129 @@ +<?php +/** + * Class QROutputAbstract + * + * @filesource QROutputAbstract.php + * @created 09.12.2015 + * @package chillerlan\QRCode\Output + * @author Smiley <smiley@chillerlan.net> + * @copyright 2015 Smiley + * @license MIT + */ + +namespace chillerlan\QRCode\Output; + +use chillerlan\QRCode\{Data\QRMatrix, QRCode}; +use chillerlan\Settings\SettingsContainerInterface; + +use function call_user_func_array, dirname, file_put_contents, get_called_class, in_array, is_writable, sprintf; + +/** + * common output abstract + */ +abstract class QROutputAbstract implements QROutputInterface{ + + /** + * the current size of the QR matrix + * + * @see \chillerlan\QRCode\Data\QRMatrix::size() + */ + protected int $moduleCount; + + /** + * the current output mode + * + * @see \chillerlan\QRCode\QROptions::$outputType + */ + protected string $outputMode; + + /** + * the default output mode of the current output module + */ + protected string $defaultMode; + + /** + * the current scaling for a QR pixel + * + * @see \chillerlan\QRCode\QROptions::$scale + */ + protected int $scale; + + /** + * the side length of the QR image (modules * scale) + */ + protected int $length; + + /** + * an (optional) array of color values for the several QR matrix parts + */ + protected array $moduleValues; + + /** + * the (filled) data matrix object + */ + protected QRMatrix $matrix; + + /** + * @var \chillerlan\Settings\SettingsContainerInterface|\chillerlan\QRCode\QROptions + */ + protected SettingsContainerInterface $options; + + /** + * QROutputAbstract constructor. + */ + public function __construct(SettingsContainerInterface $options, QRMatrix $matrix){ + $this->options = $options; + $this->matrix = $matrix; + $this->moduleCount = $this->matrix->size(); + $this->scale = $this->options->scale; + $this->length = $this->moduleCount * $this->scale; + + $class = get_called_class(); + + if(isset(QRCode::OUTPUT_MODES[$class]) && in_array($this->options->outputType, QRCode::OUTPUT_MODES[$class])){ + $this->outputMode = $this->options->outputType; + } + + $this->setModuleValues(); + } + + /** + * Sets the initial module values (clean-up & defaults) + */ + abstract protected function setModuleValues():void; + + /** + * saves the qr data to a file + * + * @see file_put_contents() + * @see \chillerlan\QRCode\QROptions::cachefile + * + * @throws \chillerlan\QRCode\Output\QRCodeOutputException + */ + protected function saveToFile(string $data, string $file):bool{ + + if(!is_writable(dirname($file))){ + throw new QRCodeOutputException(sprintf('Could not write data to cache file: %s', $file)); + } + + return (bool)file_put_contents($file, $data); + } + + /** + * @inheritDoc + */ + public function dump(string $file = null){ + $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); + } + + return $data; + } + +} |