Skip to content

Commit

Permalink
Merge pull request #9 from pluswerk/TYPO3-12
Browse files Browse the repository at this point in the history
  • Loading branch information
Kanti authored Apr 25, 2023
2 parents 4b8d52c + 81053d9 commit c1083a9
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 30 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ '7.4', '8.0', '8.1' ]
typo3: [ '10', '11' ]
php: [ '8.0', '8.1', '8.2' ]
typo3: [ '11', '12' ]
exclude:
- php: '8.0'
typo3: '10'
- php: '8.1'
typo3: '10'
typo3: '12'
steps:
- name: Setup PHP with PECL extension
uses: shivammathur/setup-php@v2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
vendor
public
composer.lock
var/
3 changes: 2 additions & 1 deletion Classes/Middleware/MinifyMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
// minimize only html
$response = $handler->handle($request);
foreach ($response->getHeader('Content-Type') as $contentType) {
if (strpos($contentType, 'text/html') !== 0) {
if (!str_starts_with($contentType, 'text/html')) {
return $response;
}
}
Expand All @@ -37,6 +37,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
$body->write($html);
$response = $response->withBody($body);
}

return $response;
}
}
10 changes: 6 additions & 4 deletions Classes/Service/MinifyService.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@ public function minify(string $html): string
$htmlMin->doRemoveOmittedQuotes($this->isFeatureActive('remove_omitted_quotes'));
$htmlMin->doRemoveOmittedHtmlTags($this->isFeatureActive('remove_omitted_html_tags'));
$htmlMin->doRemoveComments($this->isFeatureActive('remove_comments'));

$originalHtml = $html;

// Not nice but this is really hardcoded in the core.
if ($this->isFeatureActive('remove_comments')) {
$typo3Comment = $this->preserveTypo3Comment($html);
$html = $htmlMin->minify($html);
$output = [];
$languageMeta = preg_match_all('/<meta charset=[a-zA-Z0-9-_"]*>/', $html, $output);
$languageMeta = preg_match_all('#<meta charset=[a-zA-Z0-9-_"]*>#', $html, $output);
if ($languageMeta) {
$insertAt = strpos($html, $output[0][0]) + strlen($output[0][0]);
$insertAt = strpos($html, (string)$output[0][0]) + strlen($output[0][0]);
$html = substr($html, 0, $insertAt) . $typo3Comment . substr($html, $insertAt);
} else {
$html = $htmlMin->minify($html);
Expand All @@ -48,8 +49,9 @@ public function minify(string $html): string
}

if (empty($html)) {
$html = $originalHtml;
return $originalHtml;
}

return $html;
}

Expand All @@ -66,7 +68,7 @@ protected function preserveTypo3Comment(string $html): string
$typo3CommentStop = strpos($html, '-->', $typo3CommentStart);
$typo3Comment = substr($html, $typo3CommentStart, $typo3CommentStop - $typo3CommentStart + 3);

if (strpos($typo3Comment, 'TYPO3') !== false) {
if (str_contains($typo3Comment, 'TYPO3')) {
return $typo3Comment;
}

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\PlusMinify\Middleware\MinifyMiddleware;

return [
'frontend' => [
'minify/service/htmlminifier' => [
'target' => \Pluswerk\PlusMinify\Middleware\MinifyMiddleware::class,
'target' => MinifyMiddleware::class,
// in the request direction it is after these middlewares:
// but in response direction it is before these middlewares:
'after' => [
Expand Down
23 changes: 10 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,25 @@
"typo3/cms-composer-installers": true,
"typo3/class-alias-loader": true,
"phpro/grumphp": true,
"pluswerk/grumphp-config": true
"pluswerk/grumphp-config": true,
"phpstan/extension-installer": true
},
"sort-packages": true
},
"extra" : {
"typo3/cms" : {
"extension-key" : "minify"
},
"pluswerk/grumphp-config": {
"auto-setting": true
},
"grumphp": {
"config-default-path": "vendor/pluswerk/grumphp-config/grumphp.yml"
"typo3/cms": {
"extension-key": "minify"
}
},
"require" : {
"php": "~7.4 || ~8.0 || ~8.1",
"php": "~8.0 || ~8.1 || ~8.2",
"composer-runtime-api": "^2",
"typo3/cms-core": "^10.4 || ^11.5",
"voku/html-min": "^4"
"typo3/cms-core": "^11.5 || ^12.4",
"voku/html-min": "^4.5"
},
"require-dev": {
"pluswerk/grumphp-config": "^5"
"pluswerk/grumphp-config": "^6",
"saschaegerer/phpstan-typo3": "^1.8.2",
"ssch/typo3-rector": "^1.1.3"
}
}
10 changes: 4 additions & 6 deletions ext_emconf.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Composer\InstalledVersions;

/** @var string $_EXTKEY */
$EM_CONF[$_EXTKEY] = [
'title' => '+Pluswerk: Minify',
Expand All @@ -8,14 +10,10 @@
'author' => 'Stefan Lamm',
'author_email' => '[email protected]',
'state' => 'stable',
'internal' => '',
'uploadfolder' => '0',
'createDirs' => '',
'clearCacheOnLoad' => false,
'version' => \Composer\InstalledVersions::getPrettyVersion('pluswerk/minify'),
'version' => InstalledVersions::getPrettyVersion('pluswerk/minify'),
'constraints' => [
'depends' => [
'typo3' => '10.4.0 - 11.99.99',
'typo3' => '11.5.0 - 12.99.99',
],
'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
42 changes: 42 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

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 '\.php$'")))
);

// define sets of rules
$rectorConfig->sets(
[
...RectorSettings::sets(true),
...RectorSettings::setsTypo3(false),
]
);

// remove some rules
// ignore some files
$rectorConfig->skip(
[
...RectorSettings::skip(),
...RectorSettings::skipTypo3(),

/**
* rector should not touch these files
*/
//__DIR__ . '/src/Example',
//__DIR__ . '/src/Example.php',
]
);
};

0 comments on commit c1083a9

Please sign in to comment.