Skip to content

Commit

Permalink
refacto
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Beru committed Jan 13, 2025
1 parent 456c79b commit 9bdb6f7
Show file tree
Hide file tree
Showing 108 changed files with 3,285 additions and 699 deletions.
4 changes: 2 additions & 2 deletions .phpstorm.meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace PHPSTORM_META {
expectedArguments(
\Sensiolabs\GotenbergBundle\Builder\Pdf\AbstractPdfBuilder::fileName(),
\Sensiolabs\GotenbergBundle\BuilderOld\Pdf\AbstractPdfBuilder::fileName(),
1,
\Symfony\Component\HttpFoundation\HeaderUtils::DISPOSITION_INLINE,
\Symfony\Component\HttpFoundation\HeaderUtils::DISPOSITION_ATTACHMENT,
);

expectedArguments(
\Sensiolabs\GotenbergBundle\Builder\Screenshot\AbstractScreenshotBuilder::fileName(),
\Sensiolabs\GotenbergBundle\BuilderOld\Screenshot\AbstractScreenshotBuilder::fileName(),
1,
\Symfony\Component\HttpFoundation\HeaderUtils::DISPOSITION_INLINE,
\Symfony\Component\HttpFoundation\HeaderUtils::DISPOSITION_ATTACHMENT,
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"symfony/http-foundation": "^6.4 || ^7.0",
"symfony/http-kernel": "^6.4 || ^7.0",
"symfony/mime": "^6.4 || ^7.0",
"symfony/options-resolver": "^7.0",
"symfony/string": "^6.4 || ^7.0"
},
"require-dev": {
Expand Down
28 changes: 28 additions & 0 deletions config/builder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

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

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_locator([
'asset_base_dir_formatter' => service('sensiolabs_gotenberg.asset.base_dir_formatter'),
'logger' => service('logger')->nullOnInvalid(),
'request_stack' => service('request_stack')->nullOnInvalid(),
'router' => service('router')->nullOnInvalid(),
'twig' => service('twig')->nullOnInvalid(),
]),
])
;
};
137 changes: 80 additions & 57 deletions config/builder_pdf.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
<?php

use Sensiolabs\GotenbergBundle\Builder\Pdf\ConvertPdfBuilder;
use Sensiolabs\GotenbergBundle\Builder\Pdf\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\Pdf\ConvertPdfBuilder;
use Sensiolabs\GotenbergBundle\Builder\HtmlPdfBuilder;
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();
Expand All @@ -16,71 +22,88 @@
->tag('monolog.logger', ['channel' => 'sensiolabs_gotenberg'])
;

$services->set('.sensiolabs_gotenberg.pdf_builder.html', HtmlPdfBuilder::class)
->share(false)
// HTML
$services->set('.sensiolabs_gotenberg.pdf_builder_configurator.html', HtmlPdfBuilderConfigurator::class)
->args([
service('sensiolabs_gotenberg.client'),
service('sensiolabs_gotenberg.asset.base_dir_formatter'),
service('request_stack'),
service('twig')->nullOnInvalid(),
abstract_arg('default configuration'),
])
->call('setLogger', [service('logger')->nullOnInvalid()])
->tag('sensiolabs_gotenberg.pdf_builder')
;

$services->set('.sensiolabs_gotenberg.pdf_builder.url', UrlPdfBuilder::class)
$services->set('.sensiolabs_gotenberg.pdf_builder.html', HtmlPdfBuilder::class)
->share(false)
->args([
service('sensiolabs_gotenberg.client'),
service('sensiolabs_gotenberg.asset.base_dir_formatter'),
service('request_stack'),
service('twig')->nullOnInvalid(),
service('router')->nullOnInvalid(),
])
->call('setLogger', [service('logger')->nullOnInvalid()])
->call('setRequestContext', [service('.sensiolabs_gotenberg.request_context')->nullOnInvalid()])
->parent('.sensiolabs_gotenberg.abstract_builder')
->configurator(service('.sensiolabs_gotenberg.pdf_builder_configurator.html'))
->tag('sensiolabs_gotenberg.builder')
->tag('sensiolabs_gotenberg.pdf_builder')
;

$services->set('.sensiolabs_gotenberg.pdf_builder.markdown', MarkdownPdfBuilder::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.pdf_builder')
;
// $services->set('.sensiolabs_gotenberg.pdf_builder.html', HtmlPdfBuilder::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.pdf_builder')
// ;
//
// $services->set('.sensiolabs_gotenberg.pdf_builder.url', UrlPdfBuilder::class)
// ->share(false)
// ->args([
// service('sensiolabs_gotenberg.client'),
// service('sensiolabs_gotenberg.asset.base_dir_formatter'),
// service('request_stack'),
// service('twig')->nullOnInvalid(),
// service('router')->nullOnInvalid(),
// ])
// ->call('setLogger', [service('logger')->nullOnInvalid()])
// ->call('setRequestContext', [service('.sensiolabs_gotenberg.request_context')->nullOnInvalid()])
// ->tag('sensiolabs_gotenberg.pdf_builder')
// ;
//
// $services->set('.sensiolabs_gotenberg.pdf_builder.markdown', MarkdownPdfBuilder::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.pdf_builder')
// ;
//
// $services->set('.sensiolabs_gotenberg.pdf_builder.office', LibreOfficePdfBuilder::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')
// ;

$services->set('.sensiolabs_gotenberg.pdf_builder.office', LibreOfficePdfBuilder::class)
->share(false)
// Merge
$services->set('.sensiolabs_gotenberg.pdf_builder_configurator.merge', MergePdfBuilderConfigurator::class)
->args([
service('sensiolabs_gotenberg.client'),
service('sensiolabs_gotenberg.asset.base_dir_formatter'),
abstract_arg('default configuration'),
])
->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()])
->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([
service('sensiolabs_gotenberg.client'),
service('sensiolabs_gotenberg.asset.base_dir_formatter'),
])
->call('setLogger', [service('logger')->nullOnInvalid()])
->tag('sensiolabs_gotenberg.pdf_builder')
;
// $services->set('.sensiolabs_gotenberg.pdf_builder.convert', ConvertPdfBuilder::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')
// ;
};
70 changes: 37 additions & 33 deletions config/builder_screenshot.php
Original file line number Diff line number Diff line change
@@ -1,10 +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;


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

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

$services->set('.sensiolabs_gotenberg.screenshot_builder.url', UrlScreenshotBuilder::class)
$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(),
service('router')->nullOnInvalid(),
])
->call('setLogger', [service('logger')->nullOnInvalid()])
->call('setRequestContext', [service('.sensiolabs_gotenberg.request_context')->nullOnInvalid()])
->parent('.sensiolabs_gotenberg.abstract_builder')
->configurator(service('.sensiolabs_gotenberg.screenshot_builder_configurator.html'))
->tag('sensiolabs_gotenberg.builder')
->tag('sensiolabs_gotenberg.screenshot_builder')
;

$services->set('.sensiolabs_gotenberg.screenshot_builder.markdown', MarkdownScreenshotBuilder::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')
;
// $services->set('.sensiolabs_gotenberg.screenshot_builder.url', UrlScreenshotBuilder::class)
// ->share(false)
// ->args([
// service('sensiolabs_gotenberg.client'),
// service('sensiolabs_gotenberg.asset.base_dir_formatter'),
// service('request_stack'),
// service('twig')->nullOnInvalid(),
// service('router')->nullOnInvalid(),
// ])
// ->call('setLogger', [service('logger')->nullOnInvalid()])
// ->call('setRequestContext', [service('.sensiolabs_gotenberg.request_context')->nullOnInvalid()])
// ->tag('sensiolabs_gotenberg.screenshot_builder')
// ;
//
// $services->set('.sensiolabs_gotenberg.screenshot_builder.markdown', MarkdownScreenshotBuilder::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')
// ;
};
2 changes: 1 addition & 1 deletion config/debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
->args([
service('sensiolabs_gotenberg.pdf'),
service('sensiolabs_gotenberg.screenshot'),
tagged_locator('sensiolabs_gotenberg.pdf_builder'),
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'])
Expand Down
14 changes: 7 additions & 7 deletions docs/generate.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env php
<?php

use Sensiolabs\GotenbergBundle\Builder\Pdf\HtmlPdfBuilder;
use Sensiolabs\GotenbergBundle\Builder\Pdf\LibreOfficePdfBuilder;
use Sensiolabs\GotenbergBundle\Builder\Pdf\MarkdownPdfBuilder;
use Sensiolabs\GotenbergBundle\Builder\Pdf\UrlPdfBuilder;
use Sensiolabs\GotenbergBundle\Builder\Screenshot\HtmlScreenshotBuilder;
use Sensiolabs\GotenbergBundle\Builder\Screenshot\MarkdownScreenshotBuilder;
use Sensiolabs\GotenbergBundle\Builder\Screenshot\UrlScreenshotBuilder;
use Sensiolabs\GotenbergBundle\BuilderOld\Pdf\HtmlPdfBuilder;
use Sensiolabs\GotenbergBundle\BuilderOld\Pdf\LibreOfficePdfBuilder;
use Sensiolabs\GotenbergBundle\BuilderOld\Pdf\MarkdownPdfBuilder;
use Sensiolabs\GotenbergBundle\BuilderOld\Pdf\UrlPdfBuilder;
use Sensiolabs\GotenbergBundle\BuilderOld\Screenshot\HtmlScreenshotBuilder;
use Sensiolabs\GotenbergBundle\BuilderOld\Screenshot\MarkdownScreenshotBuilder;
use Sensiolabs\GotenbergBundle\BuilderOld\Screenshot\UrlScreenshotBuilder;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand Down
Loading

0 comments on commit 9bdb6f7

Please sign in to comment.