fix:更新已知bug,优化代码
This commit is contained in:
9
vendor/endroid/qr-code/src/Label/Alignment/LabelAlignmentCenter.php
vendored
Normal file
9
vendor/endroid/qr-code/src/Label/Alignment/LabelAlignmentCenter.php
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Endroid\QrCode\Label\Alignment;
|
||||
|
||||
final class LabelAlignmentCenter implements LabelAlignmentInterface
|
||||
{
|
||||
}
|
||||
9
vendor/endroid/qr-code/src/Label/Alignment/LabelAlignmentInterface.php
vendored
Normal file
9
vendor/endroid/qr-code/src/Label/Alignment/LabelAlignmentInterface.php
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Endroid\QrCode\Label\Alignment;
|
||||
|
||||
interface LabelAlignmentInterface
|
||||
{
|
||||
}
|
||||
9
vendor/endroid/qr-code/src/Label/Alignment/LabelAlignmentLeft.php
vendored
Normal file
9
vendor/endroid/qr-code/src/Label/Alignment/LabelAlignmentLeft.php
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Endroid\QrCode\Label\Alignment;
|
||||
|
||||
final class LabelAlignmentLeft implements LabelAlignmentInterface
|
||||
{
|
||||
}
|
||||
9
vendor/endroid/qr-code/src/Label/Alignment/LabelAlignmentRight.php
vendored
Normal file
9
vendor/endroid/qr-code/src/Label/Alignment/LabelAlignmentRight.php
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Endroid\QrCode\Label\Alignment;
|
||||
|
||||
final class LabelAlignmentRight implements LabelAlignmentInterface
|
||||
{
|
||||
}
|
||||
36
vendor/endroid/qr-code/src/Label/Font/Font.php
vendored
Normal file
36
vendor/endroid/qr-code/src/Label/Font/Font.php
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Endroid\QrCode\Label\Font;
|
||||
|
||||
final class Font implements FontInterface
|
||||
{
|
||||
private string $path;
|
||||
private int $size;
|
||||
|
||||
public function __construct(string $path, int $size = 16)
|
||||
{
|
||||
$this->validatePath($path);
|
||||
|
||||
$this->path = $path;
|
||||
$this->size = $size;
|
||||
}
|
||||
|
||||
private function validatePath(string $path): void
|
||||
{
|
||||
if (!file_exists($path)) {
|
||||
throw new \Exception(sprintf('Invalid font path "%s"', $path));
|
||||
}
|
||||
}
|
||||
|
||||
public function getPath(): string
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
public function getSize(): int
|
||||
{
|
||||
return $this->size;
|
||||
}
|
||||
}
|
||||
12
vendor/endroid/qr-code/src/Label/Font/FontInterface.php
vendored
Normal file
12
vendor/endroid/qr-code/src/Label/Font/FontInterface.php
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Endroid\QrCode\Label\Font;
|
||||
|
||||
interface FontInterface
|
||||
{
|
||||
public function getPath(): string;
|
||||
|
||||
public function getSize(): int;
|
||||
}
|
||||
25
vendor/endroid/qr-code/src/Label/Font/NotoSans.php
vendored
Normal file
25
vendor/endroid/qr-code/src/Label/Font/NotoSans.php
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Endroid\QrCode\Label\Font;
|
||||
|
||||
final class NotoSans implements FontInterface
|
||||
{
|
||||
private int $size;
|
||||
|
||||
public function __construct(int $size = 16)
|
||||
{
|
||||
$this->size = $size;
|
||||
}
|
||||
|
||||
public function getPath(): string
|
||||
{
|
||||
return __DIR__.'/../../../assets/noto_sans.otf';
|
||||
}
|
||||
|
||||
public function getSize(): int
|
||||
{
|
||||
return $this->size;
|
||||
}
|
||||
}
|
||||
25
vendor/endroid/qr-code/src/Label/Font/OpenSans.php
vendored
Normal file
25
vendor/endroid/qr-code/src/Label/Font/OpenSans.php
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Endroid\QrCode\Label\Font;
|
||||
|
||||
final class OpenSans implements FontInterface
|
||||
{
|
||||
private int $size;
|
||||
|
||||
public function __construct(int $size = 16)
|
||||
{
|
||||
$this->size = $size;
|
||||
}
|
||||
|
||||
public function getPath(): string
|
||||
{
|
||||
return __DIR__.'/../../../assets/open_sans.ttf';
|
||||
}
|
||||
|
||||
public function getSize(): int
|
||||
{
|
||||
return $this->size;
|
||||
}
|
||||
}
|
||||
102
vendor/endroid/qr-code/src/Label/Label.php
vendored
Normal file
102
vendor/endroid/qr-code/src/Label/Label.php
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Endroid\QrCode\Label;
|
||||
|
||||
use Endroid\QrCode\Color\Color;
|
||||
use Endroid\QrCode\Color\ColorInterface;
|
||||
use Endroid\QrCode\Label\Alignment\LabelAlignmentCenter;
|
||||
use Endroid\QrCode\Label\Alignment\LabelAlignmentInterface;
|
||||
use Endroid\QrCode\Label\Font\Font;
|
||||
use Endroid\QrCode\Label\Font\FontInterface;
|
||||
use Endroid\QrCode\Label\Margin\Margin;
|
||||
use Endroid\QrCode\Label\Margin\MarginInterface;
|
||||
|
||||
final class Label implements LabelInterface
|
||||
{
|
||||
private string $text;
|
||||
private FontInterface $font;
|
||||
private LabelAlignmentInterface $alignment;
|
||||
private MarginInterface $margin;
|
||||
private ColorInterface $textColor;
|
||||
|
||||
public function __construct(
|
||||
string $text,
|
||||
FontInterface $font = null,
|
||||
LabelAlignmentInterface $alignment = null,
|
||||
MarginInterface $margin = null,
|
||||
ColorInterface $textColor = null
|
||||
) {
|
||||
$this->text = $text;
|
||||
$this->font = $font ?? new Font(__DIR__.'/../../assets/noto_sans.otf', 16);
|
||||
$this->alignment = $alignment ?? new LabelAlignmentCenter();
|
||||
$this->margin = $margin ?? new Margin(0, 10, 10, 10);
|
||||
$this->textColor = $textColor ?? new Color(0, 0, 0);
|
||||
}
|
||||
|
||||
public static function create(string $text): self
|
||||
{
|
||||
return new self($text);
|
||||
}
|
||||
|
||||
public function getText(): string
|
||||
{
|
||||
return $this->text;
|
||||
}
|
||||
|
||||
public function setText(string $text): self
|
||||
{
|
||||
$this->text = $text;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFont(): FontInterface
|
||||
{
|
||||
return $this->font;
|
||||
}
|
||||
|
||||
public function setFont(FontInterface $font): self
|
||||
{
|
||||
$this->font = $font;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAlignment(): LabelAlignmentInterface
|
||||
{
|
||||
return $this->alignment;
|
||||
}
|
||||
|
||||
public function setAlignment(LabelAlignmentInterface $alignment): self
|
||||
{
|
||||
$this->alignment = $alignment;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMargin(): MarginInterface
|
||||
{
|
||||
return $this->margin;
|
||||
}
|
||||
|
||||
public function setMargin(MarginInterface $margin): self
|
||||
{
|
||||
$this->margin = $margin;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTextColor(): ColorInterface
|
||||
{
|
||||
return $this->textColor;
|
||||
}
|
||||
|
||||
public function setTextColor(ColorInterface $textColor): self
|
||||
{
|
||||
$this->textColor = $textColor;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
23
vendor/endroid/qr-code/src/Label/LabelInterface.php
vendored
Normal file
23
vendor/endroid/qr-code/src/Label/LabelInterface.php
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Endroid\QrCode\Label;
|
||||
|
||||
use Endroid\QrCode\Color\ColorInterface;
|
||||
use Endroid\QrCode\Label\Alignment\LabelAlignmentInterface;
|
||||
use Endroid\QrCode\Label\Font\FontInterface;
|
||||
use Endroid\QrCode\Label\Margin\MarginInterface;
|
||||
|
||||
interface LabelInterface
|
||||
{
|
||||
public function getText(): string;
|
||||
|
||||
public function getFont(): FontInterface;
|
||||
|
||||
public function getAlignment(): LabelAlignmentInterface;
|
||||
|
||||
public function getMargin(): MarginInterface;
|
||||
|
||||
public function getTextColor(): ColorInterface;
|
||||
}
|
||||
52
vendor/endroid/qr-code/src/Label/Margin/Margin.php
vendored
Normal file
52
vendor/endroid/qr-code/src/Label/Margin/Margin.php
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Endroid\QrCode\Label\Margin;
|
||||
|
||||
final class Margin implements MarginInterface
|
||||
{
|
||||
private int $top;
|
||||
private int $right;
|
||||
private int $bottom;
|
||||
private int $left;
|
||||
|
||||
public function __construct(int $top, int $right, int $bottom, int $left)
|
||||
{
|
||||
$this->top = $top;
|
||||
$this->right = $right;
|
||||
$this->bottom = $bottom;
|
||||
$this->left = $left;
|
||||
}
|
||||
|
||||
public function getTop(): int
|
||||
{
|
||||
return $this->top;
|
||||
}
|
||||
|
||||
public function getRight(): int
|
||||
{
|
||||
return $this->right;
|
||||
}
|
||||
|
||||
public function getBottom(): int
|
||||
{
|
||||
return $this->bottom;
|
||||
}
|
||||
|
||||
public function getLeft(): int
|
||||
{
|
||||
return $this->left;
|
||||
}
|
||||
|
||||
/** @return array<string, int> */
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'top' => $this->top,
|
||||
'right' => $this->right,
|
||||
'bottom' => $this->bottom,
|
||||
'left' => $this->left,
|
||||
];
|
||||
}
|
||||
}
|
||||
19
vendor/endroid/qr-code/src/Label/Margin/MarginInterface.php
vendored
Normal file
19
vendor/endroid/qr-code/src/Label/Margin/MarginInterface.php
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Endroid\QrCode\Label\Margin;
|
||||
|
||||
interface MarginInterface
|
||||
{
|
||||
public function getTop(): int;
|
||||
|
||||
public function getRight(): int;
|
||||
|
||||
public function getBottom(): int;
|
||||
|
||||
public function getLeft(): int;
|
||||
|
||||
/** @return array<string, int> */
|
||||
public function toArray(): array;
|
||||
}
|
||||
Reference in New Issue
Block a user