Skip to content

Commit c54fbea

Browse files
committed
[TASK] Make sets conditional
Activate extension sets whenever the extension dependency is available. The bootstrap-package/full set is manipulated during SetCollector compilation (that is: during cache warmup).
1 parent a04a042 commit c54fbea

File tree

16 files changed

+185
-9
lines changed

16 files changed

+185
-9
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,16 @@ jobs:
6868
if: ${{ always() && steps.install.conclusion == 'success' }}
6969
run: |
7070
composer cgl:ci
71-
- id: phpstan
71+
- id: phpstan-v12
7272
name: PHPStan
73-
if: ${{ always() && steps.install.conclusion == 'success' }}
73+
if: ${{ always() && steps.install.conclusion == 'success' && matrix.typo3 == '^12' }}
74+
run: |
75+
composer phpstan-v12 -- --error-format=github
76+
- id: phpstan-v13
77+
name: PHPStan
78+
if: ${{ always() && steps.install.conclusion == 'success' && matrix.typo3 != '^12' }}
7479
run: |
75-
composer phpstan -- --error-format=github
80+
composer phpstan-v13 -- --error-format=github
7681
- id: tests_unit
7782
name: Unit Tests
7883
if: ${{ always() && steps.install.conclusion == 'success' && matrix.php == '8.3' }}

Build/phpstan-baseline-v12.neon

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Call to an undefined static method TYPO3\\\\CMS\\\\Core\\\\Package\\\\AbstractServiceProvider\\:\\:configureSetCollector\\(\\)\\.$#"
5+
count: 1
6+
path: ../Classes/ServiceProvider.php
7+
8+
-
9+
message: "#^Class TYPO3\\\\CMS\\\\Core\\\\Site\\\\Set\\\\SetCollector not found\\.$#"
10+
count: 1
11+
path: ../Classes/ServiceProvider.php
12+
13+
-
14+
message: "#^Instantiated class TYPO3\\\\CMS\\\\Core\\\\Site\\\\Set\\\\SetDefinition not found\\.$#"
15+
count: 1
16+
path: ../Classes/ServiceProvider.php
17+
18+
-
19+
message: "#^Method BK2K\\\\BootstrapPackage\\\\ServiceProvider\\:\\:configureSetCollector\\(\\) has invalid return type TYPO3\\\\CMS\\\\Core\\\\Site\\\\Set\\\\SetCollector\\.$#"
20+
count: 1
21+
path: ../Classes/ServiceProvider.php
22+
23+
-
24+
message: "#^Parameter \\$setCollector of method BK2K\\\\BootstrapPackage\\\\ServiceProvider\\:\\:configureSetCollector\\(\\) has invalid type TYPO3\\\\CMS\\\\Core\\\\Site\\\\Set\\\\SetCollector\\.$#"
25+
count: 1
26+
path: ../Classes/ServiceProvider.php

Build/phpstan-v12.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
includes:
2+
- %currentWorkingDirectory%/Build/phpstan.neon
3+
- %currentWorkingDirectory%/Build/phpstan-baseline-v12.neon

Build/phpstan-v13.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
includes:
2+
- %currentWorkingDirectory%/Build/phpstan.neon
3+
- %currentWorkingDirectory%/Build/phpstan-baseline-v13.neon

Build/phpstan.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ includes:
33
- %currentWorkingDirectory%/.build/vendor/phpstan/phpstan-strict-rules/rules.neon
44
- %currentWorkingDirectory%/.build/vendor/phpstan/phpstan-deprecation-rules/rules.neon
55
- %currentWorkingDirectory%/.build/vendor/friendsoftypo3/phpstan-typo3/extension.neon
6-
- %currentWorkingDirectory%/Build/phpstan-baseline-v13.neon
76

87
parameters:
98
level: 8

Classes/ServiceProvider.php

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php declare(strict_types=1);
2+
3+
/*
4+
* This file is part of the package bk2k/bootstrap-package.
5+
*
6+
* For the full copyright and license information, please read the
7+
* LICENSE file that was distributed with this source code.
8+
*/
9+
10+
namespace BK2K\BootstrapPackage;
11+
12+
use Psr\Container\ContainerInterface;
13+
use TYPO3\CMS\Core\Information\Typo3Version;
14+
use TYPO3\CMS\Core\Package\AbstractServiceProvider;
15+
use TYPO3\CMS\Core\Package\PackageManager;
16+
use TYPO3\CMS\Core\Site\Set\SetCollector;
17+
use TYPO3\CMS\Core\Site\Set\SetDefinition;
18+
19+
/**
20+
* @internal
21+
*/
22+
class ServiceProvider extends AbstractServiceProvider
23+
{
24+
protected static function getPackagePath(): string
25+
{
26+
return __DIR__ . '/../';
27+
}
28+
29+
protected static function getPackageName(): string
30+
{
31+
return 'bk2k/bootstrap-package';
32+
}
33+
34+
public function getFactories(): array
35+
{
36+
return [];
37+
}
38+
39+
public function getExtensions(): array
40+
{
41+
if ((new Typo3Version)->getMajorVersion() <= 12) {
42+
return parent::getExtensions();
43+
}
44+
45+
return [
46+
SetCollector::class => [ static::class, 'configureSetCollector' ],
47+
] + parent::getExtensions();
48+
}
49+
50+
public static function configureSetCollector(ContainerInterface $container, SetCollector $setCollector, ?string $path = null): SetCollector
51+
{
52+
$setCollector = parent::configureSetCollector($container, $setCollector, $path);
53+
$availableSets = $setCollector->getSetDefinitions();
54+
$bpFullSet = $availableSets['bootstrap-package/full'] ?? null;
55+
if ($bpFullSet === null) {
56+
return $setCollector;
57+
}
58+
59+
$optionalDependencies = [];
60+
if (isset($availableSets['typo3/form'])) {
61+
$optionalDependencies[] = 'bootstrap-package/ext-form';
62+
}
63+
if (isset($availableSets['typo3/seo-sitemap'])) {
64+
$optionalDependencies[] = 'bootstrap-package/ext-seo';
65+
}
66+
if (isset($availableSets['typo3/indexed-search'])) {
67+
$optionalDependencies[] = 'bootstrap-package/ext-indexed-search';
68+
}
69+
// TODO: Introspect `$availableSets` once EXT:container provides a set
70+
if ($container->get(PackageManager::class)->isPackageActive('container')) {
71+
$optionalDependencies[] = 'bootstrap-package/ext-container';
72+
}
73+
74+
$setCollector->add(
75+
new SetDefinition(...[
76+
...$bpFullSet->toArray(),
77+
'dependencies' => [
78+
...$bpFullSet->dependencies,
79+
...$optionalDependencies,
80+
],
81+
])
82+
);
83+
return $setCollector;
84+
}
85+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
name: bootstrap-package/ext-container
2+
label: 'Bootstrap Package: EXT:container integration'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import 'EXT:bootstrap_package/Configuration/TypoScript/Extension/Container/setup.typoscript'
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name: bootstrap-package/ext-form
2+
label: 'Bootstrap Package: EXT:form integration'
3+
dependencies:
4+
- typo3/form
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name: bootstrap-package/ext-indexed-search
2+
label: 'Bootstrap Package: EXT:indexed_search integration'
3+
dependencies:
4+
- typo3/indexed-search

0 commit comments

Comments
 (0)