From ec1b63037950ad4515e52a0927ccce3ebb035975 Mon Sep 17 00:00:00 2001 From: ChristianC Date: Mon, 26 Jul 2021 20:59:25 +0200 Subject: [PATCH] Added Filesystem Storage Support (#3) --- .github/workflows/ci.yml | 4 +--- README.md | 16 +++++++++++++-- src/LaravelEpcQr.php | 30 +++++++++++++++++------------ src/LaravelEpcQrServiceProvider.php | 2 +- tests/LaravelEpcQrTest.php | 14 ++++++++++++++ 5 files changed, 48 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3282ffa..7b24726 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,12 +3,10 @@ name: Tests on: push: branches: - - master + - "*" pull_request: branches: - "*" - schedule: - - cron: '0 0 * * *' jobs: php-tests: diff --git a/README.md b/README.md index ea51b11..c158db6 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ Library for generating epc qr codes for sepa payments. See https://de.wikipedia. QR-Code generation is provided by https://github.com/endroid/qr-code +If you need a more general solution without the dependencies of endroid and laravel have a look at https://github.com/smhg/sepa-qr-data-php + ### Installation Require this package in your composer.json and update composer. @@ -64,6 +66,17 @@ $result = $builder ->build(); ``` +If you want to store the output into a file use the save method + + +```php +return EPCQR::amount(150) + ->receiver('AT000000000000000000', 'ABCDATWW', 'Max Mustermann') + ->note('test') + ->purpose('AT12') + ->save('qr.png', 'mydisk'); +``` + ### More Information on EPC QR * https://de.wikipedia.org/wiki/EPC-QR-Code @@ -71,5 +84,4 @@ $result = $builder ### TODO -* Validation -* Disk Support \ No newline at end of file +* EPC Data Validation diff --git a/src/LaravelEpcQr.php b/src/LaravelEpcQr.php index c6c5123..0d75366 100644 --- a/src/LaravelEpcQr.php +++ b/src/LaravelEpcQr.php @@ -8,7 +8,7 @@ use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelMedium; use Endroid\QrCode\Writer\Result\ResultInterface; use Endroid\QrCode\Writer\SvgWriter; -use Illuminate\Filesystem\Filesystem; +use Illuminate\Filesystem\FilesystemManager; use Illuminate\Http\Response; use InvalidArgumentException; @@ -24,9 +24,9 @@ class LaravelEpcQr public const ENCODING_ISO8859_15 = 8; /** - * @var \Illuminate\Filesystem\Filesystem + * @var FilesystemManager */ - protected Filesystem $filesystem; + protected FilesystemManager $filesystemManager; /** * @var string @@ -105,7 +105,7 @@ class LaravelEpcQr /** * @var array */ - private array $encodings = [ + protected array $encodings = [ self::ENCODING_UTF_8 => 'UTF-8', self::ENCODING_ISO8859_1 => 'ISO-8859-1', self::ENCODING_ISO8859_2 => 'ISO-8859-2', @@ -117,11 +117,13 @@ class LaravelEpcQr ]; /** - * @param \Illuminate\Filesystem\Filesystem $filesystem + * @param FilesystemManager $filesystemManager + * + * @return void */ - public function __construct(Filesystem $filesystem) + public function __construct(FilesystemManager $filesystemManager) { - $this->filesystem = $filesystem; + $this->filesystemManager = $filesystemManager; } /** @@ -380,12 +382,16 @@ public function stream(): Response } /** - * @return static + * @param string $filename + * @param string|null $disk + * + * @return bool */ - public function save(string $filename = 'qr.png'): self + public function save(string $filename = 'qr.png', ?string $disk = null): bool { - $this->filesystem->put($filename, $this->build()->getString()); - - return $this; + return $this->filesystemManager->disk($disk)->put( + $filename, + $this->build()->getString() + ); } } diff --git a/src/LaravelEpcQrServiceProvider.php b/src/LaravelEpcQrServiceProvider.php index 85aa7fc..3d53c7d 100644 --- a/src/LaravelEpcQrServiceProvider.php +++ b/src/LaravelEpcQrServiceProvider.php @@ -12,7 +12,7 @@ class LaravelEpcQrServiceProvider extends ServiceProvider public function register() { $this->app->bind('epcqr', function ($app) { - return new LaravelEpcQr($app['files']); + return new LaravelEpcQr($app['filesystem']); }); } } diff --git a/tests/LaravelEpcQrTest.php b/tests/LaravelEpcQrTest.php index a23c4c3..f67428f 100644 --- a/tests/LaravelEpcQrTest.php +++ b/tests/LaravelEpcQrTest.php @@ -123,4 +123,18 @@ public function testStream(): void $this->assertNotEmpty($output->getContent()); } + + /** + * @return void + */ + public function testStore(): void + { + Storage::fake('test_disk'); + + $output = EPCQR::amount(150) + ->imageFormat('svg') + ->save('test.svg', 'test_disk'); + + Storage::disk('test_disk')->assertExists('test.svg'); + } }