Skip to content
This repository has been archived by the owner on Jan 24, 2025. It is now read-only.

Commit

Permalink
Merge pull request #1 from pluswerk/feature/11
Browse files Browse the repository at this point in the history
  • Loading branch information
Kanti authored Jun 27, 2023
2 parents eeb9b76 + 4cb4074 commit d362bbd
Show file tree
Hide file tree
Showing 12 changed files with 144 additions and 23 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/tasks.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
.idea/
composer.lock
public/
vendor/
var/
19 changes: 6 additions & 13 deletions Classes/Middleware/ContentTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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+');
Expand All @@ -66,9 +57,11 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
]
);
}

break;
default:
}

return $response;
}
}
4 changes: 2 additions & 2 deletions Classes/Service/PdfGenerationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

use Mpdf\Mpdf;

class PdfGenerationService
final class PdfGenerationService
{
public function generatePdf(string $content, string $name = ''): Mpdf
{
Expand All @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion Configuration/RequestMiddlewares.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

use Pluswerk\HtmlToPdf\Middleware\ContentTypeResolver;

return [
'frontend' => [
'htmltopdf/service/contenttyperesolver' => [
'target' => \Pluswerk\HtmlToPdf\Middleware\ContentTypeResolver::class,
'target' => ContentTypeResolver::class,
'after' => [],
'before' => [
'typo3/cms-frontend/output-compression'
Expand Down
File renamed without changes
33 changes: 28 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
7 changes: 5 additions & 2 deletions ext_emconf.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php

/** @var string $_EXTKEY */

use Composer\InstalledVersions;

$EM_CONF[$_EXTKEY] = [
'title' => '+Pluswerk: Html To Pdf',
'description' => 'Generates a pdf out of the website',
Expand All @@ -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' => [],
Expand Down
16 changes: 16 additions & 0 deletions grumphp.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
parameters:
ignoreErrors: []
7 changes: 7 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
includes:
- phpstan-baseline.neon
- vendor/andersundsehr/phpstan-git-files/extension.php

parameters:
level: 8
reportUnmatchedIgnoredErrors: false
43 changes: 43 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

use Rector\DeadCode\Rector\MethodCall\RemoveEmptyMethodCallRector;
use PLUS\GrumPHPConfig\RectorSettings;
use Rector\Config\RectorConfig;
use Rector\Caching\ValueObject\Storage\FileCacheStorage;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->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',
]
);
};

0 comments on commit d362bbd

Please sign in to comment.