env and vendor added temporary
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Endroid\QrCode\Writer\Result;
|
||||
|
||||
use Endroid\QrCode\Matrix\MatrixInterface;
|
||||
|
||||
abstract class AbstractResult implements ResultInterface
|
||||
{
|
||||
public function __construct(
|
||||
private readonly MatrixInterface $matrix,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getMatrix(): MatrixInterface
|
||||
{
|
||||
return $this->matrix;
|
||||
}
|
||||
|
||||
public function getDataUri(): string
|
||||
{
|
||||
return 'data:'.$this->getMimeType().';base64,'.base64_encode($this->getString());
|
||||
}
|
||||
|
||||
public function saveToFile(string $path): void
|
||||
{
|
||||
$string = $this->getString();
|
||||
file_put_contents($path, $string);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Endroid\QrCode\Writer\Result;
|
||||
|
||||
use Endroid\QrCode\Matrix\MatrixInterface;
|
||||
|
||||
final class BinaryResult extends AbstractResult
|
||||
{
|
||||
public function __construct(MatrixInterface $matrix)
|
||||
{
|
||||
parent::__construct($matrix);
|
||||
}
|
||||
|
||||
public function getString(): string
|
||||
{
|
||||
$matrix = $this->getMatrix();
|
||||
|
||||
$binaryString = '';
|
||||
for ($rowIndex = 0; $rowIndex < $matrix->getBlockCount(); ++$rowIndex) {
|
||||
for ($columnIndex = 0; $columnIndex < $matrix->getBlockCount(); ++$columnIndex) {
|
||||
$binaryString .= $matrix->getBlockValue($rowIndex, $columnIndex);
|
||||
}
|
||||
$binaryString .= "\n";
|
||||
}
|
||||
|
||||
return $binaryString;
|
||||
}
|
||||
|
||||
public function getMimeType(): string
|
||||
{
|
||||
return 'text/plain';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Endroid\QrCode\Writer\Result;
|
||||
|
||||
use Endroid\QrCode\Color\ColorInterface;
|
||||
use Endroid\QrCode\Matrix\MatrixInterface;
|
||||
|
||||
final class ConsoleResult extends AbstractResult
|
||||
{
|
||||
private const TWO_BLOCKS = [
|
||||
0 => ' ',
|
||||
1 => "\xe2\x96\x80",
|
||||
2 => "\xe2\x96\x84",
|
||||
3 => "\xe2\x96\x88",
|
||||
];
|
||||
|
||||
private string $colorEscapeCode;
|
||||
|
||||
public function __construct(
|
||||
MatrixInterface $matrix,
|
||||
ColorInterface $foreground,
|
||||
ColorInterface $background,
|
||||
) {
|
||||
parent::__construct($matrix);
|
||||
|
||||
$this->colorEscapeCode = sprintf(
|
||||
"\e[38;2;%d;%d;%dm\e[48;2;%d;%d;%dm",
|
||||
$foreground->getRed(),
|
||||
$foreground->getGreen(),
|
||||
$foreground->getBlue(),
|
||||
$background->getRed(),
|
||||
$background->getGreen(),
|
||||
$background->getBlue()
|
||||
);
|
||||
}
|
||||
|
||||
public function getMimeType(): string
|
||||
{
|
||||
return 'text/plain';
|
||||
}
|
||||
|
||||
public function getString(): string
|
||||
{
|
||||
$matrix = $this->getMatrix();
|
||||
|
||||
$side = $matrix->getBlockCount();
|
||||
$marginLeft = $this->colorEscapeCode.self::TWO_BLOCKS[0].self::TWO_BLOCKS[0];
|
||||
$marginRight = self::TWO_BLOCKS[0].self::TWO_BLOCKS[0]."\e[0m".PHP_EOL;
|
||||
$marginVertical = $marginLeft.str_repeat(self::TWO_BLOCKS[0], $side).$marginRight;
|
||||
|
||||
$qrCodeString = $marginVertical;
|
||||
for ($rowIndex = 0; $rowIndex < $side; $rowIndex += 2) {
|
||||
$qrCodeString .= $marginLeft;
|
||||
for ($columnIndex = 0; $columnIndex < $side; ++$columnIndex) {
|
||||
$combined = $matrix->getBlockValue($rowIndex, $columnIndex);
|
||||
if ($rowIndex + 1 < $side) {
|
||||
$combined |= $matrix->getBlockValue($rowIndex + 1, $columnIndex) << 1;
|
||||
}
|
||||
$qrCodeString .= self::TWO_BLOCKS[$combined];
|
||||
}
|
||||
$qrCodeString .= $marginRight;
|
||||
}
|
||||
$qrCodeString .= $marginVertical;
|
||||
|
||||
return $qrCodeString;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Endroid\QrCode\Writer\Result;
|
||||
|
||||
use Endroid\QrCode\Label\LabelInterface;
|
||||
use Endroid\QrCode\Logo\LogoInterface;
|
||||
use Endroid\QrCode\Matrix\MatrixInterface;
|
||||
use Endroid\QrCode\QrCodeInterface;
|
||||
|
||||
final class DebugResult extends AbstractResult
|
||||
{
|
||||
private bool $validateResult = false;
|
||||
|
||||
public function __construct(
|
||||
MatrixInterface $matrix,
|
||||
private readonly QrCodeInterface $qrCode,
|
||||
private readonly ?LogoInterface $logo = null,
|
||||
private readonly ?LabelInterface $label = null,
|
||||
/** @var array<string, mixed> $options */
|
||||
private readonly array $options = [],
|
||||
) {
|
||||
parent::__construct($matrix);
|
||||
}
|
||||
|
||||
public function setValidateResult(bool $validateResult): void
|
||||
{
|
||||
$this->validateResult = $validateResult;
|
||||
}
|
||||
|
||||
public function getString(): string
|
||||
{
|
||||
$debugLines = [];
|
||||
|
||||
$debugLines[] = 'Data: '.$this->qrCode->getData();
|
||||
$debugLines[] = 'Encoding: '.$this->qrCode->getEncoding();
|
||||
$debugLines[] = 'Error Correction Level: '.get_class($this->qrCode->getErrorCorrectionLevel());
|
||||
$debugLines[] = 'Size: '.$this->qrCode->getSize();
|
||||
$debugLines[] = 'Margin: '.$this->qrCode->getMargin();
|
||||
$debugLines[] = 'Round block size mode: '.get_class($this->qrCode->getRoundBlockSizeMode());
|
||||
$debugLines[] = 'Foreground color: ['.implode(', ', $this->qrCode->getForegroundColor()->toArray()).']';
|
||||
$debugLines[] = 'Background color: ['.implode(', ', $this->qrCode->getBackgroundColor()->toArray()).']';
|
||||
|
||||
foreach ($this->options as $key => $value) {
|
||||
$debugLines[] = 'Writer option: '.$key.': '.$value;
|
||||
}
|
||||
|
||||
if (isset($this->logo)) {
|
||||
$debugLines[] = 'Logo path: '.$this->logo->getPath();
|
||||
$debugLines[] = 'Logo resize to width: '.$this->logo->getResizeToWidth();
|
||||
$debugLines[] = 'Logo resize to height: '.$this->logo->getResizeToHeight();
|
||||
$debugLines[] = 'Logo punchout background: '.($this->logo->getPunchoutBackground() ? 'true' : 'false');
|
||||
}
|
||||
|
||||
if (isset($this->label)) {
|
||||
$debugLines[] = 'Label text: '.$this->label->getText();
|
||||
$debugLines[] = 'Label font path: '.$this->label->getFont()->getPath();
|
||||
$debugLines[] = 'Label font size: '.$this->label->getFont()->getSize();
|
||||
$debugLines[] = 'Label alignment: '.get_class($this->label->getAlignment());
|
||||
$debugLines[] = 'Label margin: ['.implode(', ', $this->label->getMargin()->toArray()).']';
|
||||
$debugLines[] = 'Label text color: ['.implode(', ', $this->label->getTextColor()->toArray()).']';
|
||||
}
|
||||
|
||||
$debugLines[] = 'Validate result: '.($this->validateResult ? 'true' : 'false');
|
||||
|
||||
return implode("\n", $debugLines);
|
||||
}
|
||||
|
||||
public function getMimeType(): string
|
||||
{
|
||||
return 'text/plain';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Endroid\QrCode\Writer\Result;
|
||||
|
||||
use Endroid\QrCode\Matrix\MatrixInterface;
|
||||
|
||||
final class EpsResult extends AbstractResult
|
||||
{
|
||||
public function __construct(
|
||||
MatrixInterface $matrix,
|
||||
/** @var array<string> $lines */
|
||||
private readonly array $lines,
|
||||
) {
|
||||
parent::__construct($matrix);
|
||||
}
|
||||
|
||||
public function getString(): string
|
||||
{
|
||||
return implode("\n", $this->lines);
|
||||
}
|
||||
|
||||
public function getMimeType(): string
|
||||
{
|
||||
return 'image/eps';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Endroid\QrCode\Writer\Result;
|
||||
|
||||
use Endroid\QrCode\Matrix\MatrixInterface;
|
||||
|
||||
class GdResult extends AbstractResult
|
||||
{
|
||||
public function __construct(
|
||||
MatrixInterface $matrix,
|
||||
protected readonly \GdImage $image,
|
||||
) {
|
||||
parent::__construct($matrix);
|
||||
}
|
||||
|
||||
public function getImage(): \GdImage
|
||||
{
|
||||
return $this->image;
|
||||
}
|
||||
|
||||
public function getString(): string
|
||||
{
|
||||
throw new \Exception('You can only use this method in a concrete implementation');
|
||||
}
|
||||
|
||||
public function getMimeType(): string
|
||||
{
|
||||
throw new \Exception('You can only use this method in a concrete implementation');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Endroid\QrCode\Writer\Result;
|
||||
|
||||
final class GifResult extends GdResult
|
||||
{
|
||||
public function getString(): string
|
||||
{
|
||||
ob_start();
|
||||
imagegif($this->image);
|
||||
|
||||
return strval(ob_get_clean());
|
||||
}
|
||||
|
||||
public function getMimeType(): string
|
||||
{
|
||||
return 'image/gif';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Endroid\QrCode\Writer\Result;
|
||||
|
||||
use Endroid\QrCode\Matrix\MatrixInterface;
|
||||
|
||||
final class PdfResult extends AbstractResult
|
||||
{
|
||||
public function __construct(
|
||||
MatrixInterface $matrix,
|
||||
private readonly \FPDF $fpdf,
|
||||
) {
|
||||
parent::__construct($matrix);
|
||||
}
|
||||
|
||||
public function getPdf(): \FPDF
|
||||
{
|
||||
return $this->fpdf;
|
||||
}
|
||||
|
||||
public function getString(): string
|
||||
{
|
||||
return $this->fpdf->Output('S');
|
||||
}
|
||||
|
||||
public function getMimeType(): string
|
||||
{
|
||||
return 'application/pdf';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Endroid\QrCode\Writer\Result;
|
||||
|
||||
use Endroid\QrCode\Matrix\MatrixInterface;
|
||||
|
||||
final class PngResult extends GdResult
|
||||
{
|
||||
public function __construct(
|
||||
MatrixInterface $matrix,
|
||||
\GdImage $image,
|
||||
private readonly int $quality = -1,
|
||||
private readonly ?int $numberOfColors = null,
|
||||
) {
|
||||
parent::__construct($matrix, $image);
|
||||
}
|
||||
|
||||
public function getString(): string
|
||||
{
|
||||
ob_start();
|
||||
if (null !== $this->numberOfColors) {
|
||||
imagetruecolortopalette($this->image, false, $this->numberOfColors);
|
||||
}
|
||||
imagepng($this->image, quality: $this->quality);
|
||||
|
||||
return strval(ob_get_clean());
|
||||
}
|
||||
|
||||
public function getMimeType(): string
|
||||
{
|
||||
return 'image/png';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Endroid\QrCode\Writer\Result;
|
||||
|
||||
use Endroid\QrCode\Matrix\MatrixInterface;
|
||||
|
||||
interface ResultInterface
|
||||
{
|
||||
public function getMatrix(): MatrixInterface;
|
||||
|
||||
public function getString(): string;
|
||||
|
||||
public function getDataUri(): string;
|
||||
|
||||
public function saveToFile(string $path): void;
|
||||
|
||||
public function getMimeType(): string;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Endroid\QrCode\Writer\Result;
|
||||
|
||||
use Endroid\QrCode\Matrix\MatrixInterface;
|
||||
|
||||
final class SvgResult extends AbstractResult
|
||||
{
|
||||
public function __construct(
|
||||
MatrixInterface $matrix,
|
||||
private readonly \SimpleXMLElement $xml,
|
||||
private readonly bool $excludeXmlDeclaration = false,
|
||||
) {
|
||||
parent::__construct($matrix);
|
||||
}
|
||||
|
||||
public function getXml(): \SimpleXMLElement
|
||||
{
|
||||
return $this->xml;
|
||||
}
|
||||
|
||||
public function getString(): string
|
||||
{
|
||||
$string = $this->xml->asXML();
|
||||
|
||||
if (!is_string($string)) {
|
||||
throw new \Exception('Could not save SVG XML to string');
|
||||
}
|
||||
|
||||
if ($this->excludeXmlDeclaration) {
|
||||
$string = str_replace("<?xml version=\"1.0\"?>\n", '', $string);
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
public function getMimeType(): string
|
||||
{
|
||||
return 'image/svg+xml';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Endroid\QrCode\Writer\Result;
|
||||
|
||||
use Endroid\QrCode\Matrix\MatrixInterface;
|
||||
|
||||
final class WebPResult extends GdResult
|
||||
{
|
||||
public function __construct(
|
||||
MatrixInterface $matrix,
|
||||
\GdImage $image,
|
||||
private readonly int $quality = -1,
|
||||
) {
|
||||
parent::__construct($matrix, $image);
|
||||
}
|
||||
|
||||
public function getString(): string
|
||||
{
|
||||
if (!function_exists('imagewebp')) {
|
||||
throw new \Exception('WebP support is not available in your GD installation');
|
||||
}
|
||||
|
||||
ob_start();
|
||||
imagewebp($this->image, quality: $this->quality);
|
||||
|
||||
return strval(ob_get_clean());
|
||||
}
|
||||
|
||||
public function getMimeType(): string
|
||||
{
|
||||
return 'image/webp';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user