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

Enable local file access in InvoicePdfFileGenerator #272

Merged
merged 7 commits into from
Mar 31, 2022

Conversation

coldic3
Copy link
Contributor

@coldic3 coldic3 commented Mar 30, 2022

Related ticket: Sylius/RefundPlugin#361

@coldic3 coldic3 force-pushed the fix/wkhtmltopdf-local-file-access branch from cb71b24 to b640c6b Compare March 30, 2022 21:45
@coldic3 coldic3 force-pushed the fix/wkhtmltopdf-local-file-access branch 2 times, most recently from 9d8dff9 to 2363220 Compare March 31, 2022 10:12
@GSadee GSadee added the Bug Confirmed bugs or bugfixes. label Mar 31, 2022
@coldic3 coldic3 force-pushed the fix/wkhtmltopdf-local-file-access branch from 2363220 to 264b909 Compare March 31, 2022 10:51
@coldic3 coldic3 requested a review from GSadee March 31, 2022 10:55
@GSadee GSadee merged commit 70faedf into Sylius:master Mar 31, 2022
@GSadee
Copy link
Member

GSadee commented Mar 31, 2022

Thank you, Kevin! 🎉

GSadee added a commit to Sylius/Sylius that referenced this pull request Mar 31, 2022
…oblems in the wkhtmltopdf (coldic3)

This PR was merged into the 1.10 branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Branch?         | 1.10
| Bug fix?        | no
| New feature?    | no
| BC breaks?      | no
| Deprecations?   | no
| Related tickets | Sylius/RefundPlugin#361, Sylius/InvoicingPlugin#272
| License         | MIT


Commits
-------

56ed2a6 [Docs] Add a guide on how to deal with file access problems in the wkhtmltopdf
@coldic3 coldic3 deleted the fix/wkhtmltopdf-local-file-access branch March 31, 2022 11:28

use Symfony\Component\Config\FileLocatorInterface;

final class PdfOptionsGenerator implements PdfOptionsGeneratorInterface
Copy link
Member

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?

Suggested change
final class PdfOptionsGenerator implements PdfOptionsGeneratorInterface
final class PdfOptionsWithAllowedFilesProvider implements PdfOptionsProviderInterface

Copy link

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.

Comment on lines +35 to +46
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a style suggestion:

Suggested change
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;
$locatedFiles = array_map(fn ($file) => $this->fileLocator->locate($file), $this->allowedFiles);
if (!isset($options['allow'])) {
return $locatedFiles;
}
if (!is_array($options['allow'])) {
$options['allow'] = [$options['allow']];
}
$options['allow'] = array_merge(
$options['allow'],
$locatedFiles
);
return $options;

However, some cases are not covered by this class spec. For sure we do not cover the absence of $options['allow']. The case with $options['allow'] as the array is not covered as well. When can it happen?

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now $options['allow'] cannot be an array but it could be possible in the future because it makes sense so I have put this if statement to cover that case anyway 🤔

File locator throws an error for unexisting files.

) {
}

public function generate(): array
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you would follow naming change:

Suggested change
public function generate(): array
public function provide(): array

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Confirmed bugs or bugfixes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants