Skip to content

Commit

Permalink
add merge endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Beru committed Nov 18, 2024
1 parent 0a09396 commit 5827398
Show file tree
Hide file tree
Showing 33 changed files with 819 additions and 449 deletions.
21 changes: 21 additions & 0 deletions config/builder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use Sensiolabs\GotenbergBundle\Builder\AbstractBuilder;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;

return static function (ContainerConfigurator $container): void {
$services = $container->services();

$services->defaults()
->tag('monolog.logger', ['channel' => 'sensiolabs_gotenberg'])
;

$services->set('.sensiolabs_gotenberg.abstract_builder', AbstractBuilder::class)
->abstract()
->args([
service('sensiolabs_gotenberg.client'),
service('sensiolabs_gotenberg.asset.base_dir_formatter'),
])
;
};
52 changes: 28 additions & 24 deletions config/builder_pdf.php
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
<?php

// use Sensiolabs\GotenbergBundle\Builder\Pdf\ConvertPdfBuilder;
use Sensiolabs\GotenbergBundle\Builder\AbstractBuilder;
use Sensiolabs\GotenbergBundle\Builder\HtmlPdfBuilder;
// use Sensiolabs\GotenbergBundle\Builder\Pdf\LibreOfficePdfBuilder;
// use Sensiolabs\GotenbergBundle\Builder\Pdf\MarkdownPdfBuilder;
// use Sensiolabs\GotenbergBundle\Builder\Pdf\MergePdfBuilder;
// use Sensiolabs\GotenbergBundle\Builder\Pdf\UrlPdfBuilder;
use Sensiolabs\GotenbergBundle\Builder\MergePdfBuilder;
use Sensiolabs\GotenbergBundle\Configurator\HtmlPdfBuilderConfigurator;
use Sensiolabs\GotenbergBundle\Configurator\MergePdfBuilderConfigurator;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use function Symfony\Component\DependencyInjection\Loader\Configurator\abstract_arg;
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
use function Symfony\Component\DependencyInjection\Loader\Configurator\service_locator;

// use Sensiolabs\GotenbergBundle\Builder\Pdf\LibreOfficePdfBuilder;
// use Sensiolabs\GotenbergBundle\Builder\Pdf\MarkdownPdfBuilder;
// use Sensiolabs\GotenbergBundle\Builder\Pdf\MergePdfBuilder;
// use Sensiolabs\GotenbergBundle\Builder\Pdf\UrlPdfBuilder;

return static function (ContainerConfigurator $container): void {
$services = $container->services();

$services->defaults()
->tag('monolog.logger', ['channel' => 'sensiolabs_gotenberg'])
;

$services->set('.sensiolabs_gotenberg.abstract_builder', AbstractBuilder::class)
->abstract()
// HTML
$services->set('.sensiolabs_gotenberg.pdf_builder_configurator.html', HtmlPdfBuilderConfigurator::class)
->args([
service('sensiolabs_gotenberg.client'),
service('sensiolabs_gotenberg.asset.base_dir_formatter'),
abstract_arg('default body configuration'),
abstract_arg('default headers configuration'),
abstract_arg('default configuration'),
])
;

$services->set('.sensiolabs_gotenberg.pdf_builder.html', HtmlPdfBuilder::class)
->share(false)
->parent('.sensiolabs_gotenberg.abstract_builder')
->arg(4, service_locator([
->arg(2, service_locator([
'logger' => service('logger')->nullOnInvalid(),
'twig' => service('twig')->nullOnInvalid(),
'router' => service('router')->nullOnInvalid(),
]))
->configurator(service('.sensiolabs_gotenberg.pdf_builder_configurator.html'))
->tag('sensiolabs_gotenberg.builder')
->tag('sensiolabs_gotenberg.pdf_builder')
;

Expand Down Expand Up @@ -87,17 +88,20 @@
// ->call('setLogger', [service('logger')->nullOnInvalid()])
// ->tag('sensiolabs_gotenberg.pdf_builder')
// ;
//
// $services->set('.sensiolabs_gotenberg.pdf_builder.merge', MergePdfBuilder::class)
// ->share(false)
// ->args([
// service('sensiolabs_gotenberg.client'),
// service('sensiolabs_gotenberg.asset.base_dir_formatter'),
// ])
// ->call('setLogger', [service('logger')->nullOnInvalid()])
// ->tag('sensiolabs_gotenberg.pdf_builder')
// ;
//

// Merge
$services->set('.sensiolabs_gotenberg.pdf_builder_configurator.merge', MergePdfBuilderConfigurator::class)
->args([
abstract_arg('default configuration'),
])
;
$services->set('.sensiolabs_gotenberg.pdf_builder.merge', MergePdfBuilder::class)
->share(false)
->parent('.sensiolabs_gotenberg.abstract_builder')
->configurator(service('.sensiolabs_gotenberg.pdf_builder_configurator.merge'))
->tag('sensiolabs_gotenberg.pdf_builder')
;

// $services->set('.sensiolabs_gotenberg.pdf_builder.convert', ConvertPdfBuilder::class)
// ->share(false)
// ->args([
Expand Down
40 changes: 24 additions & 16 deletions config/builder_screenshot.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?php

// use Sensiolabs\GotenbergBundle\Builder\Screenshot\HtmlScreenshotBuilder;
// use Sensiolabs\GotenbergBundle\Builder\Screenshot\MarkdownScreenshotBuilder;
// use Sensiolabs\GotenbergBundle\Builder\Screenshot\UrlScreenshotBuilder;
use Sensiolabs\GotenbergBundle\Builder\HtmlScreenshotBuilder;
use Sensiolabs\GotenbergBundle\Configurator\HtmlScreenshotBuilderConfigurator;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use function Symfony\Component\DependencyInjection\Loader\Configurator\abstract_arg;
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
use function Symfony\Component\DependencyInjection\Loader\Configurator\service_locator;

// use function Symfony\Component\DependencyInjection\Loader\Configurator\service;

return static function (ContainerConfigurator $container): void {
$services = $container->services();
Expand All @@ -14,18 +15,25 @@
->tag('monolog.logger', ['channel' => 'sensiolabs_gotenberg'])
;

// $services->set('.sensiolabs_gotenberg.screenshot_builder.html', HtmlScreenshotBuilder::class)
// ->share(false)
// ->args([
// service('sensiolabs_gotenberg.client'),
// service('sensiolabs_gotenberg.asset.base_dir_formatter'),
// service('request_stack'),
// service('twig')->nullOnInvalid(),
// ])
// ->call('setLogger', [service('logger')->nullOnInvalid()])
// ->tag('sensiolabs_gotenberg.screenshot_builder')
// ;
//
// HTML
$services->set('.sensiolabs_gotenberg.screenshot_builder_configurator.html', HtmlScreenshotBuilderConfigurator::class)
->args([
abstract_arg('default configuration'),
])
;
$services->set('.sensiolabs_gotenberg.screenshot_builder.html', HtmlScreenshotBuilder::class)
->share(false)
->parent('.sensiolabs_gotenberg.abstract_builder')
->arg(2, service_locator([
'logger' => service('logger')->nullOnInvalid(),
'twig' => service('twig')->nullOnInvalid(),
'request_stack' => service('request_stack')->nullOnInvalid(),
]))
->configurator(service('.sensiolabs_gotenberg.screenshot_builder_configurator.html'))
->tag('sensiolabs_gotenberg.builder')
->tag('sensiolabs_gotenberg.screenshot_builder')
;

// $services->set('.sensiolabs_gotenberg.screenshot_builder.url', UrlScreenshotBuilder::class)
// ->share(false)
// ->args([
Expand Down
46 changes: 23 additions & 23 deletions config/debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@
return static function (ContainerConfigurator $container): void {
$services = $container->services();

// $services->set('sensiolabs_gotenberg.traceable_pdf', TraceableGotenbergPdf::class)
// ->decorate('sensiolabs_gotenberg.pdf')
// ->args([
// new Reference('.inner'),
// ])
// ;
//
// $services->set('sensiolabs_gotenberg.traceable_screenshot', TraceableGotenbergScreenshot::class)
// ->decorate('sensiolabs_gotenberg.screenshot')
// ->args([
// new Reference('.inner'),
// ])
// ;
//
// $services->set('sensiolabs_gotenberg.data_collector', GotenbergDataCollector::class)
// ->args([
// service('sensiolabs_gotenberg.pdf'),
// service('sensiolabs_gotenberg.screenshot'),
// tagged_locator('sensiolabs_gotenberg.pdf_builder'),
// abstract_arg('All default options will be set through the configuration.'),
// ])
// ->tag('data_collector', ['template' => '@SensiolabsGotenberg/Collector/sensiolabs_gotenberg.html.twig', 'id' => 'sensiolabs_gotenberg'])
// ;
$services->set('sensiolabs_gotenberg.traceable_pdf', TraceableGotenbergPdf::class)
->decorate('sensiolabs_gotenberg.pdf')
->args([
new Reference('.inner'),
])
;

$services->set('sensiolabs_gotenberg.traceable_screenshot', TraceableGotenbergScreenshot::class)
->decorate('sensiolabs_gotenberg.screenshot')
->args([
new Reference('.inner'),
])
;

$services->set('sensiolabs_gotenberg.data_collector', GotenbergDataCollector::class)
->args([
service('sensiolabs_gotenberg.pdf'),
service('sensiolabs_gotenberg.screenshot'),
tagged_locator('sensiolabs_gotenberg.builder'),
abstract_arg('All default options will be set through the configuration.'),
])
->tag('data_collector', ['template' => '@SensiolabsGotenberg/Collector/sensiolabs_gotenberg.html.twig', 'id' => 'sensiolabs_gotenberg'])
;
};
14 changes: 3 additions & 11 deletions src/Builder/AbstractBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Sensiolabs\GotenbergBundle\Builder;

use Psr\Container\ContainerInterface;
use Sensiolabs\GotenbergBundle\Builder\Behaviors\Dependencies\AssetBaseDirFormatterAwareTrait;
use Sensiolabs\GotenbergBundle\Builder\Result\GotenbergAsyncResult;
use Sensiolabs\GotenbergBundle\Builder\Result\GotenbergFileResult;
use Sensiolabs\GotenbergBundle\Client\BodyBag;
Expand All @@ -23,7 +22,6 @@
*/
abstract class AbstractBuilder implements BuilderAsyncInterface, BuilderFileInterface
{

private readonly BodyBag $bodyBag;
private readonly HeadersBag $headersBag;

Expand All @@ -32,19 +30,13 @@ abstract class AbstractBuilder implements BuilderAsyncInterface, BuilderFileInte
/** @var ProcessorInterface<mixed>|null */
private ProcessorInterface|null $processor;

/**
* @param array<string, mixed> $defaultBodyData
*/
public function __construct(
protected readonly GotenbergClientInterface $client,
protected readonly AssetBaseDirFormatter $asset,
array $defaultBodyData = [],
array $defaultHeadersData = [],
protected readonly ContainerInterface $dependencies = new Container(),
)
{
$bodyOptionsResolver = (new OptionsResolver())->setDefaults($defaultBodyData);
$headersOptionsResolver = (new OptionsResolver())->setRequired($defaultHeadersData);
) {
$bodyOptionsResolver = new OptionsResolver();
$headersOptionsResolver = new OptionsResolver();

$this->configure($bodyOptionsResolver, $headersOptionsResolver);

Expand Down
10 changes: 10 additions & 0 deletions src/Builder/Behaviors/Chromium/PagePropertiesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,14 @@ public function singlePage(bool $singlePage = true): static

return $this;
}

/**
* Sets the paper orientation to landscape.
*/
public function landscape(bool $bool = true): self
{
$this->getBodyBag()->set('landscape', $bool);

return $this;
}
}
4 changes: 4 additions & 0 deletions src/Builder/Behaviors/ChromiumTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ trait ChromiumTrait
use Chromium\HeaderFooterTrait { Chromium\HeaderFooterTrait::configure as configureHeaderFooter; }
use Chromium\PagePropertiesTrait { Chromium\PagePropertiesTrait::configure as configurePageProperties; }
use Chromium\WaitBeforeRenderingTrait { Chromium\WaitBeforeRenderingTrait::configure as configureWaitBeforeRendering; }
use MetadataTrait { MetadataTrait::configure as configureMetadata; }
use PdfFormatTrait { PdfFormatTrait::configure as configurePdfFormat; }

protected function configure(OptionsResolver $bodyOptionsResolver, OptionsResolver $headersOptionsResolver): void
{
$this->configureHeaderFooter($bodyOptionsResolver, $headersOptionsResolver);
$this->configurePageProperties($bodyOptionsResolver, $headersOptionsResolver);
$this->configureWaitBeforeRendering($bodyOptionsResolver, $headersOptionsResolver);
$this->configureMetadata($bodyOptionsResolver, $headersOptionsResolver);
$this->configurePdfFormat($bodyOptionsResolver, $headersOptionsResolver);
}
}
25 changes: 25 additions & 0 deletions src/Builder/Behaviors/LibreOffice/PagePropertiesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@

namespace Sensiolabs\GotenbergBundle\Builder\Behaviors\LibreOffice;

use Sensiolabs\GotenbergBundle\Client\BodyBag;
use Symfony\Component\OptionsResolver\OptionsResolver;

trait PagePropertiesTrait
{
abstract protected function getBodyBag(): BodyBag;

protected function configure(OptionsResolver $bodyOptionsResolver, OptionsResolver $headersOptionsResolver): void
{
$bodyOptionsResolver
->define('landscape')
->info('Set the paper orientation to landscape.')
->allowedTypes('bool')
;

// @TODO
}

/**
* Sets the paper orientation to landscape.
*/
public function landscape(bool $bool = true): self
{
$this->getBodyBag()->set('landscape', $bool);

return $this;
}
}
13 changes: 12 additions & 1 deletion src/Builder/Behaviors/LibreOfficeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@

namespace Sensiolabs\GotenbergBundle\Builder\Behaviors;

use Symfony\Component\OptionsResolver\OptionsResolver;

trait LibreOfficeTrait
{
use LibreOffice\PagePropertiesTrait;
use LibreOffice\PagePropertiesTrait { LibreOffice\PagePropertiesTrait::configure as configurePageProperties; }
use MetadataTrait { MetadataTrait::configure as configureMetadata; }
use PdfFormatTrait { PdfFormatTrait::configure as configurePdfFormat; }

protected function configure(OptionsResolver $bodyOptionsResolver, OptionsResolver $headersOptionsResolver): void
{
$this->configurePageProperties($bodyOptionsResolver, $headersOptionsResolver);
$this->configureMetadata($bodyOptionsResolver, $headersOptionsResolver);
$this->configurePdfFormat($bodyOptionsResolver, $headersOptionsResolver);
}
}
Loading

0 comments on commit 5827398

Please sign in to comment.