diff --git a/README.md b/README.md index 144b507..cf14a65 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,11 @@ Supported Stacks for now: - Laravel - Leaf PHP - Lunar +- Magento - October CMS - Shopware - Statamic +- Sylius - Symfony - Tempest - Twill diff --git a/lib/DTO/DependencyTree.php b/lib/DTO/DependencyTree.php index 5170f25..afd22e4 100644 --- a/lib/DTO/DependencyTree.php +++ b/lib/DTO/DependencyTree.php @@ -7,7 +7,9 @@ use fortrabbit\StackDetector\StackDetector\CraftCMSDetector; use fortrabbit\StackDetector\StackDetector\LunarDetector; use fortrabbit\StackDetector\StackDetector\OctoberCMSDetector; +use fortrabbit\StackDetector\StackDetector\ShopwareDetector; use fortrabbit\StackDetector\StackDetector\StatamicDetector; +use fortrabbit\StackDetector\StackDetector\SyliusDetector; use fortrabbit\StackDetector\StackDetector\TwillDetector; use fortrabbit\StackDetector\StackDetector\WinterCMSDetector; @@ -22,6 +24,10 @@ class DependencyTree WinterCMSDetector::PACKAGE_NAME, CraftCMSDetector::PACKAGE_NAME, ], + 'symfony/framework-bundle' => [ + ShopwareDetector::PACKAGE_NAME, + SyliusDetector::PACKAGE_NAME, + ], ]; /** @return string[] */ diff --git a/lib/Enum/StackType.php b/lib/Enum/StackType.php index 8a7d135..4d1b25b 100644 --- a/lib/Enum/StackType.php +++ b/lib/Enum/StackType.php @@ -16,9 +16,11 @@ enum StackType: string case LARAVEL = 'laravel'; case LEAF_PHP = 'leaf'; case LUNAR = 'lunar'; + case MAGENTO = 'magento'; case OCTOBER_CMS = 'october-cms'; case SHOPWARE = 'shopware'; case STATAMIC = 'statamic'; + case SYLIUS = 'sylius'; case SYMFONY = 'symfony'; case TEMPEST = 'tempest'; case TWILL = 'twill'; diff --git a/lib/Factory/HasStackDetectors.php b/lib/Factory/HasStackDetectors.php index c716ebb..0b3844a 100644 --- a/lib/Factory/HasStackDetectors.php +++ b/lib/Factory/HasStackDetectors.php @@ -13,8 +13,10 @@ use fortrabbit\StackDetector\StackDetector\GravCMSDetector; use fortrabbit\StackDetector\StackDetector\LeafDetector; use fortrabbit\StackDetector\StackDetector\LunarDetector; +use fortrabbit\StackDetector\StackDetector\MagentoDetector; use fortrabbit\StackDetector\StackDetector\OctoberCMSDetector; use fortrabbit\StackDetector\StackDetector\ShopwareDetector; +use fortrabbit\StackDetector\StackDetector\SyliusDetector; use fortrabbit\StackDetector\StackDetector\TempestDetector; use fortrabbit\StackDetector\StackDetector\TwillDetector; use fortrabbit\StackDetector\StackDetector\Typo3Detector; @@ -52,8 +54,10 @@ private function getStackDetectors( new GravCMSDetector($packageVersionProvider), new LeafDetector($packageVersionProvider), new LunarDetector($packageVersionProvider), + new MagentoDetector($packageVersionProvider), new OctoberCMSDetector($packageVersionProvider), new ShopwareDetector($packageVersionProvider), + new SyliusDetector($packageVersionProvider), new TempestDetector($packageVersionProvider), new TwillDetector($packageVersionProvider), new Typo3Detector($packageVersionProvider), diff --git a/lib/StackDetector/BaseComposerTypeDetector.php b/lib/StackDetector/BaseComposerTypeDetector.php index 5ee0732..087047c 100644 --- a/lib/StackDetector/BaseComposerTypeDetector.php +++ b/lib/StackDetector/BaseComposerTypeDetector.php @@ -5,6 +5,7 @@ namespace fortrabbit\StackDetector\StackDetector; use fortrabbit\StackDetector\Composer\PackageVersionProvider; +use fortrabbit\StackDetector\DTO\DependencyTree; use fortrabbit\StackDetector\DTO\Stack; use fortrabbit\StackDetector\Enum\StackType; @@ -38,4 +39,22 @@ public function getStack(string $baseUri, ?string $subDirectory): ?Stack $version->getVersion(), ); } + + /** + * True when software built on $parentPackage is installed, so the more specific detector wins. + */ + protected function hasChildStack(string $baseUri, ?string $subDirectory, string $parentPackage): bool + { + foreach (DependencyTree::getChildStacksForPackage($parentPackage) as $packageName) { + if (null !== $this->packageVersionProvider->getVersionForPackage( + $baseUri, + $subDirectory, + [$packageName], + )) { + return true; + } + } + + return false; + } } diff --git a/lib/StackDetector/LaravelDetector.php b/lib/StackDetector/LaravelDetector.php index c5f0ec9..76eb08b 100644 --- a/lib/StackDetector/LaravelDetector.php +++ b/lib/StackDetector/LaravelDetector.php @@ -4,7 +4,6 @@ namespace fortrabbit\StackDetector\StackDetector; -use fortrabbit\StackDetector\DTO\DependencyTree; use fortrabbit\StackDetector\DTO\Stack; use fortrabbit\StackDetector\StackDetectorInterface; use fortrabbit\StackDetector\Enum\StackType; @@ -23,14 +22,8 @@ protected function detectedStackType(): StackType public function getStack(string $baseUri, ?string $subDirectory): ?Stack { - foreach (DependencyTree::getChildStacksForPackage('laravel/framework') as $packageName) { - if (null !== $this->packageVersionProvider->getVersionForPackage( - $baseUri, - $subDirectory, - [$packageName], - )) { - return null; - } + if ($this->hasChildStack($baseUri, $subDirectory, 'laravel/framework')) { + return null; } return parent::getStack($baseUri, $subDirectory); diff --git a/lib/StackDetector/MagentoDetector.php b/lib/StackDetector/MagentoDetector.php new file mode 100644 index 0000000..80be84a --- /dev/null +++ b/lib/StackDetector/MagentoDetector.php @@ -0,0 +1,26 @@ +hasChildStack($baseUri, $subDirectory, 'symfony/framework-bundle')) { + return null; + } + + return parent::getStack($baseUri, $subDirectory); + } } diff --git a/tests/Unit/DetectorTest.php b/tests/Unit/DetectorTest.php index d3191dd..e21905d 100644 --- a/tests/Unit/DetectorTest.php +++ b/tests/Unit/DetectorTest.php @@ -530,9 +530,15 @@ public static function packagesDataProvider(): array 'Lunar 1' => ['lunar/1', '1', StackType::LUNAR], + 'Magento 2' => ['magento/2', '2.4.8', StackType::MAGENTO], + 'October CMS 4' => ['october_cms/4', '4', StackType::OCTOBER_CMS], 'Shopware 6' => ['shopware/6', '6.7.0', StackType::SHOPWARE], + 'Shopware 6 with Symfony in composer.lock' => ['shopware/6-locked', '6.7.3.1', StackType::SHOPWARE], + + 'Sylius 2' => ['sylius/2', '2.1', StackType::SYLIUS], + 'Sylius 2 with Symfony in composer.lock' => ['sylius/2-locked', '2.1.6', StackType::SYLIUS], 'Twill 3' => ['twill/3', '3', StackType::TWILL], diff --git a/tests/fixtures/php-stack/magento/2/composer.json b/tests/fixtures/php-stack/magento/2/composer.json new file mode 100644 index 0000000..ba7a731 --- /dev/null +++ b/tests/fixtures/php-stack/magento/2/composer.json @@ -0,0 +1,14 @@ +{ + "name": "magento/project-community-edition", + "type": "project", + "license": ["OSL-3.0", "AFL-3.0"], + "require": { + "magento/product-community-edition": "2.4.8" + }, + "repositories": [ + { + "type": "composer", + "url": "https://repo.magento.com/" + } + ] +} diff --git a/tests/fixtures/php-stack/shopware/6-locked/composer.json b/tests/fixtures/php-stack/shopware/6-locked/composer.json new file mode 100644 index 0000000..9298c30 --- /dev/null +++ b/tests/fixtures/php-stack/shopware/6-locked/composer.json @@ -0,0 +1,69 @@ +{ + "name": "shopware/production", + "license": "MIT", + "type": "project", + "require": { + "composer-runtime-api": "^2.0", + "shopware/administration": "*", + "shopware/core": "~v6.7.0", + "shopware/elasticsearch": "*", + "shopware/storefront": "*", + "symfony/flex": "~2" + }, + "repositories": [ + { + "type": "path", + "url": "custom/plugins/*", + "options": { + "symlink": true + } + }, + { + "type": "path", + "url": "custom/plugins/*/packages/*", + "options": { + "symlink": true + } + }, + { + "type": "path", + "url": "custom/static-plugins/*", + "options": { + "symlink": true + } + } + ], + "autoload": { + "psr-4": { + "App\\": "src/" + } + }, + "minimum-stability": "stable", + "prefer-stable": true, + "config": { + "allow-plugins": { + "symfony/flex": true, + "symfony/runtime": true + }, + "optimize-autoloader": true, + "sort-packages": true + }, + "scripts": { + "auto-scripts": [], + "post-install-cmd": [ + "@auto-scripts" + ], + "post-update-cmd": [ + "@auto-scripts" + ] + }, + "extra": { + "symfony": { + "allow-contrib": true, + "endpoint": [ + "https://raw.githubusercontent.com/shopware/recipes/flex/main/index.json", + "flex://defaults" + ] + } + } +} \ No newline at end of file diff --git a/tests/fixtures/php-stack/shopware/6-locked/composer.lock b/tests/fixtures/php-stack/shopware/6-locked/composer.lock new file mode 100644 index 0000000..1fb1ec3 --- /dev/null +++ b/tests/fixtures/php-stack/shopware/6-locked/composer.lock @@ -0,0 +1,8 @@ +{ + "content-hash": "0ff5bf63dfe00c079888b47286b794c9", + "packages": [ + { "name": "shopware/core", "version": "v6.7.3.1", "type": "library" }, + { "name": "symfony/framework-bundle", "version": "v7.3.4", "type": "symfony-bundle" } + ], + "packages-dev": [] +} diff --git a/tests/fixtures/php-stack/sylius/2-locked/composer.json b/tests/fixtures/php-stack/sylius/2-locked/composer.json new file mode 100644 index 0000000..74b7b2f --- /dev/null +++ b/tests/fixtures/php-stack/sylius/2-locked/composer.json @@ -0,0 +1,12 @@ +{ + "name": "sylius/sylius-standard", + "type": "project", + "license": "MIT", + "require": { + "php": "^8.2", + "sylius/sylius": "~2.1.0", + "symfony/dotenv": "^6.4 || ^7.2", + "symfony/flex": "^2.4", + "symfony/runtime": "^6.4 || ^7.2" + } +} diff --git a/tests/fixtures/php-stack/sylius/2-locked/composer.lock b/tests/fixtures/php-stack/sylius/2-locked/composer.lock new file mode 100644 index 0000000..d9c4d8c --- /dev/null +++ b/tests/fixtures/php-stack/sylius/2-locked/composer.lock @@ -0,0 +1,8 @@ +{ + "content-hash": "0ff5bf63dfe00c079888b47286b794c9", + "packages": [ + { "name": "sylius/sylius", "version": "v2.1.6", "type": "library" }, + { "name": "symfony/framework-bundle", "version": "v7.3.4", "type": "symfony-bundle" } + ], + "packages-dev": [] +} diff --git a/tests/fixtures/php-stack/sylius/2/composer.json b/tests/fixtures/php-stack/sylius/2/composer.json new file mode 100644 index 0000000..74b7b2f --- /dev/null +++ b/tests/fixtures/php-stack/sylius/2/composer.json @@ -0,0 +1,12 @@ +{ + "name": "sylius/sylius-standard", + "type": "project", + "license": "MIT", + "require": { + "php": "^8.2", + "sylius/sylius": "~2.1.0", + "symfony/dotenv": "^6.4 || ^7.2", + "symfony/flex": "^2.4", + "symfony/runtime": "^6.4 || ^7.2" + } +}