Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Filesystem Storage Support #3

Merged
merged 3 commits into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ name: Tests
on:
push:
branches:
- master
- "*"
pull_request:
branches:
- "*"
schedule:
- cron: '0 0 * * *'

jobs:
php-tests:
Expand Down
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -64,12 +66,22 @@ $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
* https://www.stuzza.at/de/download/qr-code.html

### TODO

* Validation
* Disk Support
* EPC Data Validation
30 changes: 18 additions & 12 deletions src/LaravelEpcQr.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down Expand Up @@ -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',
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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()
);
}
}
2 changes: 1 addition & 1 deletion src/LaravelEpcQrServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
});
}
}
14 changes: 14 additions & 0 deletions tests/LaravelEpcQrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}