1 | <?php |
||
2 | |||
3 | namespace Mostafaznv\PdfOptimizer; |
||
4 | |||
5 | use Mostafaznv\PdfOptimizer\Actions\OptimizePdfAction; |
||
6 | use Mostafaznv\PdfOptimizer\Concerns\ExportsScript; |
||
7 | use Mostafaznv\PdfOptimizer\Concerns\PdfOptimizerProperties; |
||
8 | use Mostafaznv\PdfOptimizer\DTOs\OptimizeResult; |
||
9 | use Psr\Log\LoggerInterface; |
||
10 | |||
11 | |||
12 | class PdfOptimizer |
||
13 | { |
||
14 | use PdfOptimizerProperties, ExportsScript; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
15 | |||
16 | private ?LoggerInterface $logger = null; |
||
17 | |||
18 | |||
19 | public function __construct( |
||
20 | private readonly string $gsBinary = 'gs', |
||
21 | ) {} |
||
22 | |||
23 | public static function init(string $gsBinary = 'gs'): self |
||
24 | { |
||
25 | return new self($gsBinary); |
||
26 | } |
||
27 | |||
28 | |||
29 | public function logger(LoggerInterface $logger): self |
||
30 | { |
||
31 | $this->logger = $logger; |
||
32 | |||
33 | return $this; |
||
34 | } |
||
35 | |||
36 | public function optimize(string $pathToFile, string $pathToOptimizedFile): OptimizeResult |
||
37 | { |
||
38 | return OptimizePdfAction::init() |
||
39 | ->logger($this->logger) |
||
40 | ->setTimeout($this->timeout) |
||
41 | ->execute( |
||
42 | command: $this->command(), |
||
43 | input: $pathToFile, |
||
44 | output: $pathToOptimizedFile |
||
45 | ); |
||
46 | } |
||
47 | } |
||
48 |