Completed
Push — master ( 738fa2...1a053c )
by Mikołaj
07:26 queued 34s
created

InvoicePdfFileGenerator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 11
nc 1
nop 5
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
    /**
23
     * @var FilenameGeneratorInterface
24
     */
25
    private $filenameGenerator;
26
27
    /**
28
     * @var GeneratorInterface
29
     */
30
    private $pdfFileGenerator;
31
32
    /**
33
     * @var EngineInterface
34
     */
35
    private $templatingEngine;
36
37
    /**
38
     * @var CompanyDataResolverInterface
39
     */
40
    private $companyDataResolver;
41
42
    /**
43
     * @var string
44
     */
45
    private $filesPath;
46
47
    /**
48
     * @param GeneratorInterface $pdfFileGenerator
49
     * @param EngineInterface $templatingEngine
50
     * @param CompanyDataResolverInterface $companyDataResolver
51
     * @param FilenameGeneratorInterface $filenameGenerator
52
     * @param string $filesPath
53
     */
54
    public function __construct(
55
        GeneratorInterface $pdfFileGenerator,
56
        EngineInterface $templatingEngine,
57
        CompanyDataResolverInterface $companyDataResolver,
58
        FilenameGeneratorInterface $filenameGenerator,
59
        string $filesPath
60
    ) {
61
        $this->pdfFileGenerator = $pdfFileGenerator;
62
        $this->templatingEngine = $templatingEngine;
63
        $this->companyDataResolver = $companyDataResolver;
64
        $this->filenameGenerator = $filenameGenerator;
65
        $this->filesPath = $filesPath;
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function generateFile(InvoiceInterface $invoice): string
72
    {
73
        $html = $this->templatingEngine->render(
74
            'BitBagSyliusInvoicingPlugin::invoice.html.twig', [
75
                'invoice' => $invoice,
76
                'companyData' => $this->companyDataResolver->resolveCompanyData(),
77
            ]
78
        );
79
        $filename = $this->filenameGenerator->generateFilename($invoice);
80
        $path = $this->filesPath . DIRECTORY_SEPARATOR . $filename;
81
        
82
        $this->pdfFileGenerator->generateFromHtml($html, $path);
83
84
        return $filename;
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90
    public function getFilesDirectoryPath(): string
91
    {
92
        return $this->filesPath;
93
    }
94
}
95