Skip to content

Commit 35b81b8

Browse files
committed
[UPDATE] Some minor changes
1 parent 0e5caff commit 35b81b8

12 files changed

+43
-89
lines changed

.phpstorm.meta.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace PHPSTORM_META {
4+
expectedArguments(
5+
\Sensiolabs\GotenbergBundle\Builder\AbstractPdfBuilder::fileName(),
6+
1,
7+
\Symfony\Component\HttpFoundation\HeaderUtils::DISPOSITION_INLINE,
8+
\Symfony\Component\HttpFoundation\HeaderUtils::DISPOSITION_ATTACHMENT,
9+
);
10+
}

config/services.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use function Symfony\Component\DependencyInjection\Loader\Configurator\abstract_arg;
1717
use function Symfony\Component\DependencyInjection\Loader\Configurator\param;
1818
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
19+
use function Symfony\Component\DependencyInjection\Loader\Configurator\tagged_locator;
1920

2021
return function (ContainerConfigurator $container): void {
2122
$services = $container->services();
@@ -81,7 +82,7 @@
8182

8283
$services->set('sensiolabs_gotenberg', Gotenberg::class)
8384
->args([
84-
abstract_arg('All builders indexed by class FQCN')
85+
tagged_locator('sensiolabs_gotenberg.builder'),
8586
])
8687
->alias(GotenbergInterface::class, 'sensiolabs_gotenberg')
8788
;

src/Builder/AbstractChromiumPdfBuilder.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ public function nativePageRanges(string $range): static
194194
}
195195

196196
/**
197+
* @param string $template #Template
197198
* @param array<string, mixed> $context
198199
*
199200
* @throws PdfPartRenderingException if the template could not be rendered
@@ -204,6 +205,7 @@ public function header(string $template, array $context = []): static
204205
}
205206

206207
/**
208+
* @param string $template #Template
207209
* @param array<string, mixed> $context
208210
*
209211
* @throws PdfPartRenderingException if the template could not be rendered
@@ -439,6 +441,7 @@ protected function withPdfPartFile(PdfPart $pdfPart, string $path): static
439441
}
440442

441443
/**
444+
* @param string $template #Template
442445
* @param array<string, mixed> $context
443446
*
444447
* @throws PdfPartRenderingException if the template could not be rendered

src/Builder/HtmlPdfBuilder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ final class HtmlPdfBuilder extends AbstractChromiumPdfBuilder
1111
private const ENDPOINT = '/forms/chromium/convert/html';
1212

1313
/**
14+
* @param string $template #Template
1415
* @param array<string, mixed> $context
1516
*
1617
* @throws PdfPartRenderingException if the template could not be rendered

src/Builder/MarkdownPdfBuilder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ final class MarkdownPdfBuilder extends AbstractChromiumPdfBuilder
1515
/**
1616
* The HTML file that wraps the markdown content, rendered from a Twig template.
1717
*
18+
* @param string $template #Template
1819
* @param array<string, mixed> $context
1920
*
2021
* @throws PdfPartRenderingException if the template could not be rendered

src/Client/PdfResponse.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace Sensiolabs\GotenbergBundle\Client;
44

5-
use Symfony\Component\Filesystem\Filesystem;
65
use Symfony\Component\HttpFoundation\Response;
7-
use Symfony\Component\HttpKernel\Exception\HttpException;
86
use Symfony\Contracts\HttpClient\ResponseInterface;
97

108
class PdfResponse extends Response
@@ -13,17 +11,4 @@ public function __construct(public ResponseInterface $response)
1311
{
1412
parent::__construct($response->getContent(), $response->getStatusCode(), $response->getHeaders());
1513
}
16-
17-
public function saveTo(string $filename): string
18-
{
19-
$file = new Filesystem();
20-
21-
try {
22-
$file->dumpFile($filename, $this->response->getContent());
23-
} catch (\Exception $exception) {
24-
throw new HttpException(500, $exception->getMessage());
25-
}
26-
27-
return $filename;
28-
}
2914
}

src/DependencyInjection/CompilerPass/ProcessBuildersPass.php

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/DependencyInjection/SensiolabsGotenbergExtension.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ public function load(array $configs, ContainerBuilder $container): void
4444
}
4545

4646
/**
47-
* @param array<string, mixed> $userConfigurations
47+
* @template T of array<string, mixed>
4848
*
49-
* @return array<string, mixed>
49+
* @param T $userConfigurations
50+
*
51+
* @return array<key-of<T>, value-of<T>>
5052
*/
5153
private function cleanUserOptions(array $userConfigurations): array
5254
{

src/Pdf/Gotenberg.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,39 @@ public function get(string $builder): PdfBuilderInterface
2121
return $this->container->get($builder);
2222
}
2323

24+
/**
25+
* @param 'html'|'url'|'markdown'|'office' $key
26+
*
27+
* @return (
28+
* $key is 'html' ? HtmlPdfBuilder :
29+
* $key is 'url' ? UrlPdfBuilder :
30+
* $key is 'office' ? LibreOfficePdfBuilder :
31+
* $key is 'markdown' ? MarkdownPdfBuilder :
32+
* PdfBuilderInterface
33+
* )
34+
*/
35+
private function getInternal(string $key): PdfBuilderInterface
36+
{
37+
return $this->get(".sensiolabs_gotenberg.builder.{$key}");
38+
}
39+
2440
public function html(): HtmlPdfBuilder
2541
{
26-
return $this->get(HtmlPdfBuilder::class);
42+
return $this->getInternal('html');
2743
}
2844

2945
public function url(): UrlPdfBuilder
3046
{
31-
return $this->get(UrlPdfBuilder::class);
47+
return $this->getInternal('url');
3248
}
3349

3450
public function office(): LibreOfficePdfBuilder
3551
{
36-
return $this->get(LibreOfficePdfBuilder::class);
52+
return $this->getInternal('office');
3753
}
3854

3955
public function markdown(): MarkdownPdfBuilder
4056
{
41-
return $this->get(MarkdownPdfBuilder::class);
57+
return $this->getInternal('markdown');
4258
}
4359
}

src/Pdf/GotenbergInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ interface GotenbergInterface
1313
/**
1414
* @template T of PdfBuilderInterface
1515
*
16-
* @param class-string<T> $builder
16+
* @param string|class-string<T> $builder
1717
*
18-
* @return T
18+
* @return ($builder is class-string<T> ? T : PdfBuilderInterface)
1919
*/
2020
public function get(string $builder): PdfBuilderInterface;
2121

src/SensiolabsGotenbergBundle.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,8 @@
22

33
namespace Sensiolabs\GotenbergBundle;
44

5-
use Sensiolabs\GotenbergBundle\DependencyInjection\CompilerPass\ProcessBuildersPass;
6-
use Symfony\Component\DependencyInjection\ContainerBuilder;
75
use Symfony\Component\HttpKernel\Bundle\Bundle;
86

97
class SensiolabsGotenbergBundle extends Bundle
108
{
11-
public function build(ContainerBuilder $container)
12-
{
13-
$container->addCompilerPass(new ProcessBuildersPass());
14-
}
159
}

tests/Client/PdfResponseTest.php

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)