Skip to content

Commit

Permalink
[UPDATE] Some minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Neirda24 committed Mar 25, 2024
1 parent 0e5caff commit 35b81b8
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 89 deletions.
10 changes: 10 additions & 0 deletions .phpstorm.meta.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace PHPSTORM_META {
expectedArguments(
\Sensiolabs\GotenbergBundle\Builder\AbstractPdfBuilder::fileName(),
1,
\Symfony\Component\HttpFoundation\HeaderUtils::DISPOSITION_INLINE,
\Symfony\Component\HttpFoundation\HeaderUtils::DISPOSITION_ATTACHMENT,
);
}
3 changes: 2 additions & 1 deletion config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use function Symfony\Component\DependencyInjection\Loader\Configurator\abstract_arg;
use function Symfony\Component\DependencyInjection\Loader\Configurator\param;
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
use function Symfony\Component\DependencyInjection\Loader\Configurator\tagged_locator;

return function (ContainerConfigurator $container): void {
$services = $container->services();
Expand Down Expand Up @@ -81,7 +82,7 @@

$services->set('sensiolabs_gotenberg', Gotenberg::class)
->args([
abstract_arg('All builders indexed by class FQCN')
tagged_locator('sensiolabs_gotenberg.builder'),
])
->alias(GotenbergInterface::class, 'sensiolabs_gotenberg')
;
Expand Down
3 changes: 3 additions & 0 deletions src/Builder/AbstractChromiumPdfBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ public function nativePageRanges(string $range): static
}

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

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

/**
* @param string $template #Template
* @param array<string, mixed> $context
*
* @throws PdfPartRenderingException if the template could not be rendered
Expand Down
1 change: 1 addition & 0 deletions src/Builder/HtmlPdfBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ final class HtmlPdfBuilder extends AbstractChromiumPdfBuilder
private const ENDPOINT = '/forms/chromium/convert/html';

/**
* @param string $template #Template
* @param array<string, mixed> $context
*
* @throws PdfPartRenderingException if the template could not be rendered
Expand Down
1 change: 1 addition & 0 deletions src/Builder/MarkdownPdfBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ final class MarkdownPdfBuilder extends AbstractChromiumPdfBuilder
/**
* The HTML file that wraps the markdown content, rendered from a Twig template.
*
* @param string $template #Template
* @param array<string, mixed> $context
*
* @throws PdfPartRenderingException if the template could not be rendered
Expand Down
15 changes: 0 additions & 15 deletions src/Client/PdfResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace Sensiolabs\GotenbergBundle\Client;

use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Contracts\HttpClient\ResponseInterface;

class PdfResponse extends Response
Expand All @@ -13,17 +11,4 @@ public function __construct(public ResponseInterface $response)
{
parent::__construct($response->getContent(), $response->getStatusCode(), $response->getHeaders());
}

public function saveTo(string $filename): string
{
$file = new Filesystem();

try {
$file->dumpFile($filename, $this->response->getContent());
} catch (\Exception $exception) {
throw new HttpException(500, $exception->getMessage());
}

return $filename;
}
}
29 changes: 0 additions & 29 deletions src/DependencyInjection/CompilerPass/ProcessBuildersPass.php

This file was deleted.

6 changes: 4 additions & 2 deletions src/DependencyInjection/SensiolabsGotenbergExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ public function load(array $configs, ContainerBuilder $container): void
}

/**
* @param array<string, mixed> $userConfigurations
* @template T of array<string, mixed>
*
* @return array<string, mixed>
* @param T $userConfigurations
*
* @return array<key-of<T>, value-of<T>>
*/
private function cleanUserOptions(array $userConfigurations): array
{
Expand Down
24 changes: 20 additions & 4 deletions src/Pdf/Gotenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,39 @@ public function get(string $builder): PdfBuilderInterface
return $this->container->get($builder);
}

/**
* @param 'html'|'url'|'markdown'|'office' $key
*
* @return (
* $key is 'html' ? HtmlPdfBuilder :
* $key is 'url' ? UrlPdfBuilder :
* $key is 'office' ? LibreOfficePdfBuilder :
* $key is 'markdown' ? MarkdownPdfBuilder :
* PdfBuilderInterface
* )
*/
private function getInternal(string $key): PdfBuilderInterface
{
return $this->get(".sensiolabs_gotenberg.builder.{$key}");
}

public function html(): HtmlPdfBuilder
{
return $this->get(HtmlPdfBuilder::class);
return $this->getInternal('html');
}

public function url(): UrlPdfBuilder
{
return $this->get(UrlPdfBuilder::class);
return $this->getInternal('url');
}

public function office(): LibreOfficePdfBuilder
{
return $this->get(LibreOfficePdfBuilder::class);
return $this->getInternal('office');
}

public function markdown(): MarkdownPdfBuilder
{
return $this->get(MarkdownPdfBuilder::class);
return $this->getInternal('markdown');
}
}
4 changes: 2 additions & 2 deletions src/Pdf/GotenbergInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ interface GotenbergInterface
/**
* @template T of PdfBuilderInterface
*
* @param class-string<T> $builder
* @param string|class-string<T> $builder
*
* @return T
* @return ($builder is class-string<T> ? T : PdfBuilderInterface)
*/
public function get(string $builder): PdfBuilderInterface;

Expand Down
6 changes: 0 additions & 6 deletions src/SensiolabsGotenbergBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@

namespace Sensiolabs\GotenbergBundle;

use Sensiolabs\GotenbergBundle\DependencyInjection\CompilerPass\ProcessBuildersPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class SensiolabsGotenbergBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
$container->addCompilerPass(new ProcessBuildersPass());
}
}
30 changes: 0 additions & 30 deletions tests/Client/PdfResponseTest.php

This file was deleted.

0 comments on commit 35b81b8

Please sign in to comment.