Skip to content

Commit

Permalink
[WIP][TASK] Make sets conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
bnf committed Oct 17, 2024
1 parent a04a042 commit d21a5ec
Show file tree
Hide file tree
Showing 16 changed files with 184 additions and 9 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,16 @@ jobs:
if: ${{ always() && steps.install.conclusion == 'success' }}
run: |
composer cgl:ci
- id: phpstan
- id: phpstan-v12
name: PHPStan
if: ${{ always() && steps.install.conclusion == 'success' }}
if: ${{ always() && steps.install.conclusion == 'success' && matrix.typo3 == '^12' }}
run: |
composer phpstan-v12 -- --error-format=github
- id: phpstan-v13
name: PHPStan
if: ${{ always() && steps.install.conclusion == 'success' && matrix.typo3 != '^12' }}
run: |
composer phpstan -- --error-format=github
composer phpstan-v13 -- --error-format=github
- id: tests_unit
name: Unit Tests
if: ${{ always() && steps.install.conclusion == 'success' && matrix.php == '8.3' }}
Expand Down
26 changes: 26 additions & 0 deletions Build/phpstan-baseline-v12.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
parameters:
ignoreErrors:
-
message: "#^Call to an undefined static method TYPO3\\\\CMS\\\\Core\\\\Package\\\\AbstractServiceProvider\\:\\:configureSetCollector\\(\\)\\.$#"
count: 1
path: ../Classes/ServiceProvider.php

-
message: "#^Class TYPO3\\\\CMS\\\\Core\\\\Site\\\\Set\\\\SetCollector not found\\.$#"
count: 1
path: ../Classes/ServiceProvider.php

-
message: "#^Instantiated class TYPO3\\\\CMS\\\\Core\\\\Site\\\\Set\\\\SetDefinition not found\\.$#"
count: 1
path: ../Classes/ServiceProvider.php

-
message: "#^Method BK2K\\\\BootstrapPackage\\\\ServiceProvider\\:\\:configureSetCollector\\(\\) has invalid return type TYPO3\\\\CMS\\\\Core\\\\Site\\\\Set\\\\SetCollector\\.$#"
count: 1
path: ../Classes/ServiceProvider.php

-
message: "#^Parameter \\$setCollector of method BK2K\\\\BootstrapPackage\\\\ServiceProvider\\:\\:configureSetCollector\\(\\) has invalid type TYPO3\\\\CMS\\\\Core\\\\Site\\\\Set\\\\SetCollector\\.$#"
count: 1
path: ../Classes/ServiceProvider.php
3 changes: 3 additions & 0 deletions Build/phpstan-v12.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
includes:
- %currentWorkingDirectory%/Build/phpstan.neon
- %currentWorkingDirectory%/Build/phpstan-baseline-v12.neon
3 changes: 3 additions & 0 deletions Build/phpstan-v13.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
includes:
- %currentWorkingDirectory%/Build/phpstan.neon
- %currentWorkingDirectory%/Build/phpstan-baseline-v13.neon
1 change: 0 additions & 1 deletion Build/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ includes:
- %currentWorkingDirectory%/.build/vendor/phpstan/phpstan-strict-rules/rules.neon
- %currentWorkingDirectory%/.build/vendor/phpstan/phpstan-deprecation-rules/rules.neon
- %currentWorkingDirectory%/.build/vendor/friendsoftypo3/phpstan-typo3/extension.neon
- %currentWorkingDirectory%/Build/phpstan-baseline-v13.neon

parameters:
level: 8
Expand Down
84 changes: 84 additions & 0 deletions Classes/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php declare(strict_types=1);

/*
* This file is part of the package bk2k/bootstrap-package.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace BK2K\BootstrapPackage;

use Psr\Container\ContainerInterface;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Package\AbstractServiceProvider;
use TYPO3\CMS\Core\Package\PackageManager;
use TYPO3\CMS\Core\Site\Set\SetCollector;
use TYPO3\CMS\Core\Site\Set\SetDefinition;

/**
* @internal
*/
class ServiceProvider extends AbstractServiceProvider
{
protected static function getPackagePath(): string
{
return __DIR__ . '/../';
}

protected static function getPackageName(): string
{
return 'bk2k/bootstrap-package';
}

public function getFactories(): array
{
return [];
}

public function getExtensions(): array
{
if ((new Typo3Version)->getMajorVersion() <= 12) {
return parent::getExtensions();
}

return [
SetCollector::class => [ static::class, 'configureSetCollector' ],
] + parent::getExtensions();
}

public static function configureSetCollector(ContainerInterface $container, SetCollector $setCollector, ?string $path = null): SetCollector
{
$setCollector = parent::configureSetCollector($container, $setCollector, $path);
$availableSets = $setCollector->getSetDefinitions();
$bpFullSet = $availableSets['bootstrap-package/full'] ?? null;
if ($bpFullSet === null) {
return $setCollector;
}

$optionalDependencies = [];
if (isset($availableSets['typo3/form'])) {
$optionalDependencies[] = 'bootstrap-package/ext-form';
}
if (isset($availableSets['typo3/seo-sitemap'])) {
$optionalDependencies[] = 'bootstrap-package/ext-seo';
}
if (isset($availableSets['typo3/indexed-search'])) {
$optionalDependencies[] = 'bootstrap-package/ext-indexed-search';
}
if ($container->get(PackageManager::class)->isPackageActive('container')) {
$optionalDependencies[] = 'bootstrap-package/ext-container';
}

$setCollector->add(
new SetDefinition(...[
...$bpFullSet->toArray(),
'dependencies' => [
...$bpFullSet->dependencies,
...$optionalDependencies,
],
])
);
return $setCollector;
}
}
2 changes: 2 additions & 0 deletions Configuration/Sets/ExtContainer/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name: bootstrap-package/ext-container
label: 'Bootstrap Package: EXT:container integration'
1 change: 1 addition & 0 deletions Configuration/Sets/ExtContainer/setup.typoscript
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import 'EXT:bootstrap_package/Configuration/TypoScript/Extension/Container/setup.typoscript'
4 changes: 4 additions & 0 deletions Configuration/Sets/ExtForm/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: bootstrap-package/ext-form
label: 'Bootstrap Package: EXT:form integration'
dependencies:
- typo3/form
4 changes: 4 additions & 0 deletions Configuration/Sets/ExtIndexedSearch/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: bootstrap-package/ext-indexed-search
label: 'Bootstrap Package: EXT:indexed_search integration'
dependencies:
- typo3/indexed-search
16 changes: 16 additions & 0 deletions Configuration/Sets/ExtIndexedSearch/setup.typoscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
plugin.tx_indexedsearch {
view {
templateRootPaths {
20 = EXT:bootstrap_package/Resources/Private/Templates/IndexedSearch/
21 = {$plugin.bootstrap_package.view.templateRootPath}IndexedSearch/
}
partialRootPaths {
20 = EXT:bootstrap_package/Resources/Private/Partials/IndexedSearch/
21 = {$plugin.bootstrap_package.view.partialRootPath}IndexedSearch/
}
layoutRootPaths {
20 = EXT:bootstrap_package/Resources/Private/Layouts/IndexedSearch/
21 = {$plugin.bootstrap_package.view.layoutRootPath}IndexedSearch/
}
}
}
4 changes: 4 additions & 0 deletions Configuration/Sets/ExtSeo/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: bootstrap-package/ext-seo
label: 'Bootstrap Package: EXT:seo integration'
dependencies:
- typo3/seo-sitemap
16 changes: 16 additions & 0 deletions Configuration/Sets/ExtSeo/setup.typoscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
plugin.tx_seo {
view {
templateRootPaths {
20 = EXT:bootstrap_package/Resources/Private/Templates/Seo/
21 = {$plugin.bootstrap_package.view.templateRootPath}Seo/
}
partialRootPaths {
20 = EXT:bootstrap_package/Resources/Private/Partials/Seo/
21 = {$plugin.bootstrap_package.view.partialRootPath}Seo/
}
layoutRootPaths {
20 = EXT:bootstrap_package/Resources/Private/Layouts/Seo/
21 = {$plugin.bootstrap_package.view.layoutRootPath}Seo/
}
}
}
5 changes: 5 additions & 0 deletions Configuration/Sets/Full/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ dependencies:
- bootstrap-package/google-font
- bootstrap-package/google-tag-manager
- bootstrap-package/skiplink
# optional dependencies added by ServiceProvider
# - bootstrap-package/ext-form
# - bootstrap-package/ext-indexed-search
# - bootstrap-package/ext-seo-sitemap
# - bootstrap-package/ext-container
3 changes: 0 additions & 3 deletions Configuration/Sets/Full/setup.typoscript
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# DEPENDENCIES
@import 'EXT:bootstrap_package/Configuration/TypoScript/Extension/setup.typoscript'

# HELPER
@import 'EXT:bootstrap_package/Configuration/TypoScript/Helper/Block.typoscript'
@import 'EXT:bootstrap_package/Configuration/TypoScript/Helper/PageClass.typoscript'
Expand Down
10 changes: 8 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
},
"typo3/cms": {
"extension-key": "bootstrap_package",
"Package": {
"serviceProvider": "BK2K\\BootstrapPackage\\ServiceProvider"
},
"web-dir": ".build/public"
}
},
Expand Down Expand Up @@ -115,8 +118,11 @@
"changelog": [
"extension-helper changelog:create"
],
"phpstan": [
"phpstan analyze --configuration Build/phpstan.neon"
"phpstan-v12": [
"phpstan analyze --configuration Build/phpstan-v12.neon"
],
"phpstan-v13": [
"phpstan analyze --configuration Build/phpstan-v13.neon"
],
"phpstan:baseline": [
"phpstan analyze --configuration Build/phpstan.neon --generate-baseline Build/phpstan-baseline.neon"
Expand Down

0 comments on commit d21a5ec

Please sign in to comment.