Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ Supported Stacks for now:
- Laravel
- Leaf PHP
- Lunar
- Magento
- October CMS
- Shopware
- Statamic
- Sylius
- Symfony
- Tempest
- Twill
Expand Down
6 changes: 6 additions & 0 deletions lib/DTO/DependencyTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -22,6 +24,10 @@ class DependencyTree
WinterCMSDetector::PACKAGE_NAME,
CraftCMSDetector::PACKAGE_NAME,
],
'symfony/framework-bundle' => [
ShopwareDetector::PACKAGE_NAME,
SyliusDetector::PACKAGE_NAME,
],
];

/** @return string[] */
Expand Down
2 changes: 2 additions & 0 deletions lib/Enum/StackType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
4 changes: 4 additions & 0 deletions lib/Factory/HasStackDetectors.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down
19 changes: 19 additions & 0 deletions lib/StackDetector/BaseComposerTypeDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
}
11 changes: 2 additions & 9 deletions lib/StackDetector/LaravelDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
26 changes: 26 additions & 0 deletions lib/StackDetector/MagentoDetector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace fortrabbit\StackDetector\StackDetector;

use fortrabbit\StackDetector\StackDetectorInterface;
use fortrabbit\StackDetector\Enum\StackType;

class MagentoDetector extends BaseComposerTypeDetector implements StackDetectorInterface
{
protected function packagesToSearch(): array
{
// Open Source first, then Adobe Commerce; both lock magento/magento2-base.
return [
'magento/product-community-edition',
'magento/product-enterprise-edition',
'magento/magento2-base',
];
}

protected function detectedStackType(): StackType
{
return StackType::MAGENTO;
}
}
4 changes: 3 additions & 1 deletion lib/StackDetector/ShopwareDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@

class ShopwareDetector extends BaseComposerTypeDetector implements StackDetectorInterface
{
public const string PACKAGE_NAME = 'shopware/core';

protected function packagesToSearch(): array
{
return ['shopware/core'];
return [self::PACKAGE_NAME];
}

protected function detectedStackType(): StackType
Expand Down
23 changes: 23 additions & 0 deletions lib/StackDetector/SyliusDetector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace fortrabbit\StackDetector\StackDetector;

use fortrabbit\StackDetector\StackDetectorInterface;
use fortrabbit\StackDetector\Enum\StackType;

class SyliusDetector extends BaseComposerTypeDetector implements StackDetectorInterface
{
public const string PACKAGE_NAME = 'sylius/sylius';

protected function packagesToSearch(): array
{
return [self::PACKAGE_NAME];
}

protected function detectedStackType(): StackType
{
return StackType::SYLIUS;
}
}
10 changes: 10 additions & 0 deletions lib/StackDetector/SymfonyDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace fortrabbit\StackDetector\StackDetector;

use fortrabbit\StackDetector\DTO\Stack;
use fortrabbit\StackDetector\StackDetectorInterface;
use fortrabbit\StackDetector\Enum\StackType;

Expand All @@ -18,4 +19,13 @@ protected function detectedStackType(): StackType
{
return StackType::SYMFONY;
}

public function getStack(string $baseUri, ?string $subDirectory): ?Stack
{
if ($this->hasChildStack($baseUri, $subDirectory, 'symfony/framework-bundle')) {
return null;
}

return parent::getStack($baseUri, $subDirectory);
}
}
6 changes: 6 additions & 0 deletions tests/Unit/DetectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],

Expand Down
14 changes: 14 additions & 0 deletions tests/fixtures/php-stack/magento/2/composer.json
Original file line number Diff line number Diff line change
@@ -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/"
}
]
}
69 changes: 69 additions & 0 deletions tests/fixtures/php-stack/shopware/6-locked/composer.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
}
8 changes: 8 additions & 0 deletions tests/fixtures/php-stack/shopware/6-locked/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions tests/fixtures/php-stack/sylius/2-locked/composer.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
8 changes: 8 additions & 0 deletions tests/fixtures/php-stack/sylius/2-locked/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions tests/fixtures/php-stack/sylius/2/composer.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
Loading