This repository has been archived by the owner on Aug 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Invoice path relative to invoices_root_dir. Added invoice naming method. #5
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7c24c39
#4 Invoice path is now relative to invoices_root_dir. Added invoice n…
ambroisemaupate ee69d35
Code style
ambroisemaupate 96bd81f
Changed getFilesPath name, blank line with return
ambroisemaupate 533deef
Moved getInvoiceFilename method to dedicated and decorable service.
ambroisemaupate 3674802
Argument order and private member.
ambroisemaupate eb28755
Order
ambroisemaupate File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ | |
!/etc/build/.gitkeep | ||
|
||
/tests/Application/yarn.lock | ||
/.idea | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
/* | ||
* This file has been created by developers from BitBag. | ||
* Feel free to contact us once you face any issues or want to start | ||
* another great project. | ||
* You can find more information about us on https://bitbag.shop and write us | ||
* an email on mikolaj.krol@bitbag.pl. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitBag\SyliusInvoicingPlugin\FileGenerator; | ||
|
||
use BitBag\SyliusInvoicingPlugin\Entity\InvoiceInterface; | ||
|
||
interface FilenameGeneratorInterface | ||
{ | ||
/** | ||
* @param InvoiceInterface $invoice | ||
* | ||
* @return string | ||
*/ | ||
public function generateFilename(InvoiceInterface $invoice): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,11 @@ | |
|
||
final class InvoicePdfFileGenerator implements FileGeneratorInterface | ||
{ | ||
/** | ||
* @var FilenameGeneratorInterface | ||
*/ | ||
protected $filenameGenerator; | ||
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. Please, mark it as private, the class is final, so there's no need to add protected fields to it. |
||
|
||
/** | ||
* @var GeneratorInterface | ||
*/ | ||
|
@@ -44,17 +49,20 @@ final class InvoicePdfFileGenerator implements FileGeneratorInterface | |
* @param EngineInterface $templatingEngine | ||
* @param CompanyDataResolverInterface $companyDataResolver | ||
* @param string $filesPath | ||
* @param FilenameGeneratorInterface $filenameGenerator | ||
*/ | ||
public function __construct( | ||
GeneratorInterface $pdfFileGenerator, | ||
EngineInterface $templatingEngine, | ||
CompanyDataResolverInterface $companyDataResolver, | ||
string $filesPath | ||
string $filesPath, | ||
FilenameGeneratorInterface $filenameGenerator | ||
) { | ||
$this->pdfFileGenerator = $pdfFileGenerator; | ||
$this->templatingEngine = $templatingEngine; | ||
$this->companyDataResolver = $companyDataResolver; | ||
$this->filesPath = $filesPath; | ||
$this->filenameGenerator = $filenameGenerator; | ||
} | ||
|
||
/** | ||
|
@@ -68,33 +76,18 @@ public function generateFile(InvoiceInterface $invoice): string | |
'companyData' => $this->companyDataResolver->resolveCompanyData(), | ||
] | ||
); | ||
$filename = $this->getInvoiceFilename($invoice); | ||
$filename = $this->filenameGenerator->generateFilename($invoice); | ||
$path = $this->filesPath . DIRECTORY_SEPARATOR . $filename; | ||
|
||
$this->pdfFileGenerator->generateFromHtml($html, $path); | ||
|
||
return $filename; | ||
} | ||
|
||
/** | ||
* @param InvoiceInterface $invoice | ||
* @return string Returns an explicit invoice file name | ||
*/ | ||
protected function getInvoiceFilename(InvoiceInterface $invoice): string | ||
{ | ||
$tokens = [ | ||
$invoice->getOrder()->getNumber(), | ||
$invoice->getOrder()->getCreatedAt()->format('Ymd'), | ||
bin2hex(random_bytes(6)), | ||
]; | ||
|
||
return (string) implode('_', $tokens) . '.pdf'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getFilesPath(): string | ||
public function getFilesDirectoryPath(): string | ||
{ | ||
return $this->filesPath; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
/* | ||
* This file has been created by developers from BitBag. | ||
* Feel free to contact us once you face any issues or want to start | ||
* another great project. | ||
* You can find more information about us on https://bitbag.shop and write us | ||
* an email on mikolaj.krol@bitbag.pl. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitBag\SyliusInvoicingPlugin\FileGenerator; | ||
|
||
use BitBag\SyliusInvoicingPlugin\Entity\InvoiceInterface; | ||
|
||
final class InvoicePdfFilenameGenerator implements FilenameGeneratorInterface | ||
{ | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public function generateFilename(InvoiceInterface $invoice): string | ||
{ | ||
$tokens = [ | ||
$invoice->getOrder()->getNumber(), | ||
$invoice->getOrder()->getCreatedAt()->format('Ymd'), | ||
bin2hex(random_bytes(6)), | ||
]; | ||
|
||
return (string) implode('_', $tokens) . '.pdf'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,17 @@ imports: | |
- { resource: "@BitBagSyliusInvoicingPlugin/Resources/config/services/resolver.yml" } | ||
|
||
services: | ||
bitbag_sylius_invoicing_plugin.file_generator.invoice_filename: | ||
class: BitBag\SyliusInvoicingPlugin\FileGenerator\InvoicePdfFilenameGenerator | ||
|
||
bitbag_sylius_invoicing_plugin.file_generator.invoice_file: | ||
class: BitBag\SyliusInvoicingPlugin\FileGenerator\InvoicePdfFileGenerator | ||
arguments: | ||
- "@knp_snappy.pdf" | ||
- "@templating" | ||
- "@bitbag_sylius_invoicing_plugin.resolver.company_data" | ||
- "%invoices_root_dir%" | ||
- "@bitbag_sylius_invoicing_plugin.file_generator.invoice_filename" | ||
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. In our convention, we put the object types above the default types, so if possible, interfaces over strings, arrays, etc. Could you please change this order remembering the right order in __construct call as well as properties order in |
||
|
||
bitbag_sylius_invoicing_plugin.validator.vat_number: | ||
class: BitBag\SyliusInvoicingPlugin\Validator\Constraints\VatNumberValidator | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Please, remove it from the .gitignore. Configure a global .gitignore file instead. Read more here: https://gist.github.com/subfuzion/db7f57fff2fb6998a16c