|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file has been created by developers from BitBag. |
|
5
|
|
|
* Feel free to contact us once you face any issues or want to start |
|
6
|
|
|
* another great project. |
|
7
|
|
|
* You can find more information about us on https://bitbag.shop and write us |
|
8
|
|
|
* an email on [email protected]. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
declare(strict_types=1); |
|
12
|
|
|
|
|
13
|
|
|
namespace BitBag\SyliusInvoicingPlugin\FileGenerator; |
|
14
|
|
|
|
|
15
|
|
|
use BitBag\SyliusInvoicingPlugin\Entity\InvoiceInterface; |
|
16
|
|
|
use BitBag\SyliusInvoicingPlugin\Resolver\CompanyDataResolverInterface; |
|
17
|
|
|
use Knp\Snappy\GeneratorInterface; |
|
18
|
|
|
use Symfony\Component\Templating\EngineInterface; |
|
19
|
|
|
|
|
20
|
|
|
final class InvoicePdfFileGenerator implements FileGeneratorInterface |
|
21
|
|
|
{ |
|
22
|
|
|
/** @var FilenameGeneratorInterface */ |
|
23
|
|
|
private $filenameGenerator; |
|
24
|
|
|
|
|
25
|
|
|
/** @var FileGeneratorInterface */ |
|
26
|
|
|
private $pdfFileGenerator; |
|
27
|
|
|
|
|
28
|
|
|
/** @var EngineInterface */ |
|
29
|
|
|
private $templatingEngine; |
|
30
|
|
|
|
|
31
|
|
|
/** @var CompanyDataResolverInterface */ |
|
32
|
|
|
private $companyDataResolver; |
|
33
|
|
|
|
|
34
|
|
|
/** @var string */ |
|
35
|
|
|
private $filesPath; |
|
36
|
|
|
|
|
37
|
|
|
public function __construct( |
|
38
|
|
|
GeneratorInterface $pdfFileGenerator, |
|
39
|
|
|
EngineInterface $templatingEngine, |
|
40
|
|
|
CompanyDataResolverInterface $companyDataResolver, |
|
41
|
|
|
FilenameGeneratorInterface $filenameGenerator, |
|
42
|
|
|
string $filesPath |
|
43
|
|
|
) { |
|
44
|
|
|
$this->pdfFileGenerator = $pdfFileGenerator; |
|
|
|
|
|
|
45
|
|
|
$this->templatingEngine = $templatingEngine; |
|
46
|
|
|
$this->companyDataResolver = $companyDataResolver; |
|
47
|
|
|
$this->filenameGenerator = $filenameGenerator; |
|
48
|
|
|
$this->filesPath = $filesPath; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function generateFile(InvoiceInterface $invoice): string |
|
52
|
|
|
{ |
|
53
|
|
|
$html = $this->templatingEngine->render( |
|
54
|
|
|
'BitBagSyliusInvoicingPlugin::invoice.html.twig', [ |
|
55
|
|
|
'invoice' => $invoice, |
|
56
|
|
|
'companyData' => $this->companyDataResolver->resolveCompanyData(), |
|
57
|
|
|
] |
|
58
|
|
|
); |
|
59
|
|
|
$filename = $this->filenameGenerator->generateFilename($invoice); |
|
60
|
|
|
$path = $this->filesPath . DIRECTORY_SEPARATOR . $filename; |
|
61
|
|
|
|
|
62
|
|
|
$this->pdfFileGenerator->generateFromHtml($html, $path); |
|
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
return $filename; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function getFilesDirectoryPath(): string |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->filesPath; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..