diff --git a/.github/workflows/tasks.yml b/.github/workflows/tasks.yml new file mode 100644 index 0000000..0c19e23 --- /dev/null +++ b/.github/workflows/tasks.yml @@ -0,0 +1,28 @@ +name: Tasks + +on: [push, pull_request] + +jobs: + lint-php: + name: "php: ${{ matrix.php }} TYPO3: ${{ matrix.typo3 }}" + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php: [ '8.2' ] + typo3: [ '11', '12' ] + steps: + - name: Setup PHP with PECL extension + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + - uses: actions/checkout@v2 + - uses: actions/cache@v2 + with: + path: ~/.composer/cache/files + key: ${{ runner.os }}-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-${{ matrix.php }}-composer- + - run: composer require typo3/minimal="^${{ matrix.typo3 }}" --dev --ignore-platform-req=php+ + - run: composer install --no-interaction --no-progress --ignore-platform-req=php+ + - run: ./vendor/bin/grumphp run --ansi diff --git a/.gitignore b/.gitignore index 9f11b75..f996ae6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ .idea/ +composer.lock +public/ +vendor/ +var/ diff --git a/Classes/Middleware/ContentTypeResolver.php b/Classes/Middleware/ContentTypeResolver.php index 5195a29..6770721 100644 --- a/Classes/Middleware/ContentTypeResolver.php +++ b/Classes/Middleware/ContentTypeResolver.php @@ -27,14 +27,10 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; -class ContentTypeResolver implements MiddlewareInterface +final class ContentTypeResolver implements MiddlewareInterface { /** * Resolve the response content-type based on the page type - * - * @param ServerRequestInterface $request - * @param RequestHandlerInterface $handler - * @return ResponseInterface */ public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { @@ -45,14 +41,9 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface switch ((int)$pageArguments->getPageType()) { case 1590672891: - if ( - $GLOBALS['TSFE'] instanceof TypoScriptFrontendController - && $GLOBALS['TSFE']->isOutputting() - ) { - $title = 'page'; - if (isset($GLOBALS['TSFE']->page['title'])) { - $title = $GLOBALS['TSFE']->page['title']; - } + if ($GLOBALS['TSFE'] instanceof TypoScriptFrontendController) { + $title = $GLOBALS['TSFE']->page['title'] ?? 'page'; + $pdfService = GeneralUtility::makeInstance(PdfGenerationService::class); $pdf = $pdfService->generatePdf($GLOBALS['TSFE']->content, $title); $body = new Stream('php://temp', 'wb+'); @@ -66,9 +57,11 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface ] ); } + break; default: } + return $response; } } diff --git a/Classes/Service/PdfGenerationService.php b/Classes/Service/PdfGenerationService.php index 7a4808d..4724e98 100644 --- a/Classes/Service/PdfGenerationService.php +++ b/Classes/Service/PdfGenerationService.php @@ -17,7 +17,7 @@ use Mpdf\Mpdf; -class PdfGenerationService +final class PdfGenerationService { public function generatePdf(string $content, string $name = ''): Mpdf { @@ -39,7 +39,7 @@ public function generatePdf(string $content, string $name = ''): Mpdf $pdf->SetProtection(['print']); $pdf->SetDisplayMode('fullpage'); - $pdf->title = $name; + $pdf->setTitle($name); $pdf->WriteHTML($content); return $pdf; diff --git a/Configuration/RequestMiddlewares.php b/Configuration/RequestMiddlewares.php index 98b2629..14aa8e4 100644 --- a/Configuration/RequestMiddlewares.php +++ b/Configuration/RequestMiddlewares.php @@ -1,9 +1,11 @@ [ 'htmltopdf/service/contenttyperesolver' => [ - 'target' => \Pluswerk\HtmlToPdf\Middleware\ContentTypeResolver::class, + 'target' => ContentTypeResolver::class, 'after' => [], 'before' => [ 'typo3/cms-frontend/output-compression' diff --git a/ext_icon.svg b/Resources/Public/Icons/Extension.svg similarity index 100% rename from ext_icon.svg rename to Resources/Public/Icons/Extension.svg diff --git a/composer.json b/composer.json index f5f3492..24ccc92 100644 --- a/composer.json +++ b/composer.json @@ -1,19 +1,42 @@ { "name": "pluswerk/html_to_pdf", - "type": "typo3-cms-extension", "description": "Pluswerk: HTML to PDF", - "homepage": "https://www.pluswerk.ag", "license": "GPL-2.0-or-later", + "type": "typo3-cms-extension", + "homepage": "https://www.pluswerk.ag", "support": { "source": "https://www.pluswerk.ag" }, + "require": { + "php": "~8.2.0", + "composer-runtime-api": "^2.2.2", + "mpdf/mpdf": "^8.0", + "typo3/cms-core": "^11.5.0 || ^12.4.0", + "typo3/cms-frontend": "^11.5.0 || ^12.4.0" + }, + "require-dev": { + "pluswerk/grumphp-config": "^6.7", + "saschaegerer/phpstan-typo3": "^1.8.2", + "ssch/typo3-rector": "^1.1.3" + }, "autoload": { "psr-4": { "Pluswerk\\HtmlToPdf\\": "Classes/" } }, - "require": { - "typo3/cms-core": ">=9.5", - "mpdf/mpdf": "^8.0" + "config": { + "allow-plugins": { + "typo3/class-alias-loader": true, + "typo3/cms-composer-installers": true, + "phpro/grumphp": true, + "phpstan/extension-installer": true, + "ergebnis/composer-normalize": true, + "pluswerk/grumphp-config": true + } + }, + "extra": { + "typo3/cms": { + "extension-key": "html_to_pdf" + } } } diff --git a/ext_emconf.php b/ext_emconf.php index 4479e86..b146a8e 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -1,6 +1,9 @@ '+Pluswerk: Html To Pdf', 'description' => 'Generates a pdf out of the website', @@ -12,10 +15,10 @@ 'uploadfolder' => '0', 'createDirs' => '', 'clearCacheOnLoad' => 0, - 'version' => '1.0.0', + 'version' => InstalledVersions::getPrettyVersion('pluswerk/html_to_pdf'), 'constraints' => [ 'depends' => [ - 'typo3' => '9.5.0-9.99.99', + 'typo3' => '11.5.0-11.5.999', ], 'conflicts' => [], 'suggests' => [], diff --git a/grumphp.yml b/grumphp.yml new file mode 100644 index 0000000..3a60a5a --- /dev/null +++ b/grumphp.yml @@ -0,0 +1,16 @@ +imports: + - { resource: vendor/pluswerk/grumphp-config/grumphp.yml } +parameters: + convention.process_timeout: 240 + convention.security_checker_blocking: true + convention.jsonlint_ignore_pattern: { } + convention.xmllint_ignore_pattern: { } + convention.yamllint_ignore_pattern: { } + convention.phpcslint_ignore_pattern: { } + convention.phpcslint_exclude: { } + convention.xlifflint_ignore_pattern: { } + convention.rector_ignore_pattern: { } + convention.rector_enabled: true + convention.rector_config: rector.php + convention.rector_clear-cache: false + convention.phpstan_level: null diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..aab4991 --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,2 @@ +parameters: + ignoreErrors: [] diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..e178ba6 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,7 @@ +includes: + - phpstan-baseline.neon + - vendor/andersundsehr/phpstan-git-files/extension.php + +parameters: + level: 8 + reportUnmatchedIgnoredErrors: false diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..a4cd8f9 --- /dev/null +++ b/rector.php @@ -0,0 +1,43 @@ +parallel(); + $rectorConfig->importNames(); + $rectorConfig->importShortClasses(); + $rectorConfig->cacheClass(FileCacheStorage::class); + $rectorConfig->cacheDirectory('./var/cache/rector'); + + $rectorConfig->paths( + array_filter(explode("\n", (string)shell_exec("git ls-files | xargs ls -d 2>/dev/null | grep -E '\.(php|html|typoscript)$'"))) + ); + + // define sets of rules + $rectorConfig->sets( + [ + ...RectorSettings::sets(true), + ...RectorSettings::setsTypo3(false), + ] + ); + + // remove some rules + // ignore some files + $rectorConfig->skip( + [ + ...RectorSettings::skip(), + ...RectorSettings::skipTypo3(), + RemoveEmptyMethodCallRector::class, // this with Mpdf takes for ever :/ + /** + * rector should not touch these files + */ + //__DIR__ . '/src/Example', + //__DIR__ . '/src/Example.php', + ] + ); +};