|
| 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 | +} |
0 commit comments