-
-
Notifications
You must be signed in to change notification settings - Fork 86
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
Enable local file access in InvoicePdfFileGenerator #272
Changes from all commits
c8a8aee
91070d5
1eeda81
0b0d548
b640c6b
47b8a1c
264b909
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\Sylius\InvoicingPlugin\Generator; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
use Sylius\InvoicingPlugin\Generator\PdfOptionsGeneratorInterface; | ||
use Symfony\Component\Config\FileLocatorInterface; | ||
|
||
final class PdfOptionsGeneratorSpec extends ObjectBehavior | ||
{ | ||
function let(FileLocatorInterface $fileLocator): void | ||
{ | ||
$this->beConstructedWith( | ||
$fileLocator, | ||
['allow' => 'allowed_file_in_knp_snappy_config.png'], | ||
['swans.png'] | ||
); | ||
} | ||
|
||
function it_is_pdf_options_generator_interface(): void | ||
{ | ||
$this->shouldImplement(PdfOptionsGeneratorInterface::class); | ||
} | ||
|
||
function it_generates_pdf_options(FileLocatorInterface $fileLocator): void | ||
{ | ||
$fileLocator | ||
->locate('swans.png') | ||
->willReturn('located-path/swans.png'); | ||
|
||
$this | ||
->generate() | ||
->shouldBeLike([ | ||
'allow' => [ | ||
'allowed_file_in_knp_snappy_config.png', | ||
'located-path/swans.png', | ||
], | ||
]) | ||
; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,48 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<?php | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* This file is part of the Sylius package. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* (c) Paweł Jędrzejewski | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* For the full copyright and license information, please view the LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* file that was distributed with this source code. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
declare(strict_types=1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
namespace Sylius\InvoicingPlugin\Generator; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
use Symfony\Component\Config\FileLocatorInterface; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
final class PdfOptionsGenerator implements PdfOptionsGeneratorInterface | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public function __construct( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private FileLocatorInterface $fileLocator, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private array $knpSnappyOptions, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private array $allowedFiles | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public function generate(): array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you would follow naming change:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$options = $this->knpSnappyOptions; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (empty($this->allowedFiles)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return $options; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (!isset($options['allow'])) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$options['allow'] = []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} elseif (!is_array($options['allow'])) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$options['allow'] = [$options['allow']]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$options['allow'] = array_merge( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$options['allow'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
array_map(fn ($file) => $this->fileLocator->locate($file), $this->allowedFiles) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return $options; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+35
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a style suggestion:
Suggested change
However, some cases are not covered by this class spec. For sure we do not cover the absence of It is not the case for spec probably, but what will happen if the file does not exist? What is returned by the fileLocator in such a case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now File locator throws an error for unexisting files. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about this naming?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you go with "pdf options provider interface", then I would keep the interface name as an integral suffix, i.e.: "allowed files pdf options provider". As an extra improvement, I would move the "pdf" from class name to namespace.