diff --git a/composer.json b/composer.json index ef7944b4..ccc87b3f 100644 --- a/composer.json +++ b/composer.json @@ -33,163 +33,131 @@ } ], "provide": { - "psr/event-dispatcher-implementation": "1.0", + "psr/cache-implementation": "^2.0 || ^3.0", "psr/clock-implementation": "1.0", - "psr/http-message-implementation": "^1.0 || ^2.0", + "psr/container-implementation": "^1.0 || ^2.0", + "psr/event-dispatcher-implementation": "1.0", "psr/http-factory-implementation": "^1.0", - "psr/cache-implementation": "^2.0 || ^3.0", - "psr/simple-cache-implementation": "^1.0 || ^2.0 || ^3.0", + "psr/http-message-implementation": "^1.0 || ^2.0", + "psr/http-server-handler-implementation": "^1.0", + "psr/http-server-middleware-implementation": "^1.0", + "psr/link-implementation": "^1.0 || ^2.0", + "psr/log-implementation": "^1.0 || ^2.0 || ^3.0", + "psr/simple-cache-implementation": "^2.0 || ^3.0", + "sonsofphp/cookie-implementation": "0.3.x-dev", "sonsofphp/cqrs-implementation": "0.3.x-dev", "sonsofphp/event-sourcing-implementation": "0.3.x-dev", "sonsofphp/feature-toggle-implementation": "0.3.x-dev", "sonsofphp/filesystem-implementation": "0.3.x-dev", - "sonsofphp/money-implementation": "0.3.x-dev", - "sonsofphp/version-implementation": "0.3.x-dev", - "psr/log-implementation": "^1.0 || ^2.0 || ^3.0", - "sonsofphp/logger-implementation": "0.3.x-dev", - "sonsofphp/pager-implementation": "0.3.x-dev", - "psr/link-implementation": "^1.0 || ^2.0", - "sonsofphp/cookie-implementation": "0.3.x-dev", - "psr/container-implementation": "^1.0 || ^2.0", - "psr/http-server-handler-implementation": "^1.0", - "psr/http-server-middleware-implementation": "^1.0", "sonsofphp/http-handler-implementation": "0.3.x-dev", + "sonsofphp/logger-implementation": "0.3.x-dev", "sonsofphp/mailer-implementation": "0.3.x-dev", + "sonsofphp/money-implementation": "0.3.x-dev", + "sonsofphp/pager-implementation": "0.3.x-dev", + "sonsofphp/registry-implementation": "0.3.x-dev", "sonsofphp/state-machine-implementation": "0.3.x-dev", - "sonsofphp/registry-implementation": "0.3.x-dev" + "sonsofphp/version-implementation": "0.3.x-dev" }, "require": { - "php": ">=8.2", + "aws/aws-sdk-php": "^3.0", + "doctrine/collections": "^2", + "doctrine/dbal": "^3", + "doctrine/orm": "^2 || ^3", + "ext-intl": "*", "ext-json": "*", + "liip/imagine-bundle": "^2.0", + "php": ">=8.2", + "psr/cache": "^2.0 || ^3.0", + "psr/clock": "^1.0", + "psr/container": "^1.0 || ^2.0", "psr/event-dispatcher": "^1.0", - "doctrine/dbal": "^3", - "symfony/options-resolver": "^6 || ^7", - "symfony/uid": "^5 || ^6 || ^7", + "psr/http-factory": "^1.0", + "psr/http-message": "^1.0 || ^2.0", + "psr/http-server-handler": "^1.0", + "psr/http-server-middleware": "^1.0", + "psr/link": "^1.0 || ^2.0", + "psr/log": "^2.0 || ^3.0", + "psr/simple-cache": "^2.0 || ^3.0", + "sonsofphp/cookie-contract": "0.3.x-dev", + "sonsofphp/cqrs-contract": "0.3.x-dev", + "sonsofphp/event-dispatcher": "0.3.x-dev", + "sonsofphp/event-sourcing": "^0.3.x-dev", + "sonsofphp/event-sourcing-contract": "^0.3.x-dev", + "sonsofphp/feature-toggle-contract": "0.3.x-dev", + "sonsofphp/http-handler-contract": "0.3.x-dev", + "sonsofphp/http-message": "^0.3.x-dev", + "sonsofphp/json": "^0.3.x-dev", + "sonsofphp/logger": "^0.3.x-dev", + "sonsofphp/logger-contract": "0.3.x-dev", + "sonsofphp/money": "^0.3.x-dev", + "sonsofphp/money-contract": "0.3.x-dev", + "sonsofphp/pager-contract": "0.3.x-dev", + "sonsofphp/registry-contract": "0.3.x-dev", + "sonsofphp/state-machine-contract": "0.3.x-dev", + "sonsofphp/version": "^0.3.x-dev", + "sonsofphp/version-contract": "0.3.x-dev", "symfony/console": "^4 || ^5 || ^6 || ^7", + "symfony/dependency-injection": "^5 || ^6 || ^7", "symfony/dotenv": "^5 || ^6 || ^7", "symfony/finder": "^5 || ^6 || ^7", - "symfony/process": "^5 || ^6 || ^7", - "symfony/dependency-injection": "^5 || ^6 || ^7", "symfony/http-kernel": "^5 || ^6 || ^7", - "symfony/security-bundle": "^6 || ^7", "symfony/messenger": "^5 || ^6 || ^7", - "psr/clock": "^1.0", - "psr/http-message": "^1.0 || ^2.0", - "psr/http-factory": "^1.0", - "psr/cache": "^2.0 || ^3.0", - "psr/simple-cache": "^3.0", - "psr/log": "^2.0 || ^3.0", - "psr/link": "^1.0 || ^2.0", - "twig/twig": "^3.0", - "ext-intl": "*", - "doctrine/collections": "^2", - "doctrine/orm": "^2 || ^3", - "psr/container": "^1.0 || ^2.0", - "psr/http-server-handler": "^1.0", - "psr/http-server-middleware": "^1.0", - "aws/aws-sdk-php": "^3.0", - "liip/imagine-bundle": "^2.0" + "symfony/options-resolver": "^6 || ^7", + "symfony/process": "^5 || ^6 || ^7", + "symfony/security-bundle": "^6 || ^7", + "symfony/uid": "^5 || ^6 || ^7", + "twig/twig": "^3.0" }, "replace": { + "sonsofphp/assert": "self.version", "sonsofphp/bard": "self.version", + "sonsofphp/cache": "self.version", "sonsofphp/clock": "self.version", + "sonsofphp/common-contract": "self.version", + "sonsofphp/container": "self.version", + "sonsofphp/cookie": "self.version", + "sonsofphp/cookie-contract": "self.version", "sonsofphp/cqrs": "self.version", + "sonsofphp/cqrs-bundle": "self.version", + "sonsofphp/cqrs-contract": "self.version", "sonsofphp/cqrs-symfony": "self.version", "sonsofphp/event-dispatcher": "self.version", "sonsofphp/event-sourcing": "self.version", + "sonsofphp/event-sourcing-contract": "self.version", "sonsofphp/event-sourcing-doctrine": "self.version", "sonsofphp/event-sourcing-symfony": "self.version", "sonsofphp/feature-toggle": "self.version", - "sonsofphp/json": "self.version", - "sonsofphp/money": "self.version", - "sonsofphp/version": "self.version", - "sonsofphp/cqrs-bundle": "self.version", - "sonsofphp/filesystem": "self.version", - "sonsofphp/http-message": "self.version", - "sonsofphp/http-factory": "self.version", - "sonsofphp/core-contract": "self.version", - "sonsofphp/cache": "self.version", - "sonsofphp/cqrs-contract": "self.version", - "sonsofphp/event-sourcing-contract": "self.version", "sonsofphp/feature-toggle-contract": "self.version", + "sonsofphp/filesystem": "self.version", + "sonsofphp/filesystem-aws": "self.version", "sonsofphp/filesystem-contract": "self.version", - "sonsofphp/money-contract": "self.version", - "sonsofphp/version-contract": "self.version", - "sonsofphp/common-contract": "self.version", + "sonsofphp/filesystem-liip-imagine": "self.version", + "sonsofphp/http-factory": "self.version", + "sonsofphp/http-handler": "self.version", + "sonsofphp/http-handler-contract": "self.version", + "sonsofphp/http-message": "self.version", + "sonsofphp/json": "self.version", + "sonsofphp/link": "self.version", "sonsofphp/logger": "self.version", "sonsofphp/logger-contract": "self.version", - "sonsofphp/pager-contract": "self.version", - "sonsofphp/pager": "self.version", - "sonsofphp/link": "self.version", + "sonsofphp/mailer": "self.version", + "sonsofphp/mailer-contract": "self.version", + "sonsofphp/money": "self.version", + "sonsofphp/money-contract": "self.version", "sonsofphp/money-twig": "self.version", + "sonsofphp/pager": "self.version", + "sonsofphp/pager-contract": "self.version", "sonsofphp/pager-doctrine-collections": "self.version", "sonsofphp/pager-doctrine-dbal": "self.version", "sonsofphp/pager-doctrine-orm": "self.version", - "sonsofphp/cookie": "self.version", - "sonsofphp/cookie-contract": "self.version", - "sonsofphp/container": "self.version", - "sonsofphp/http-handler": "self.version", - "sonsofphp/http-handler-contract": "self.version", - "sonsofphp/mailer-contract": "self.version", - "sonsofphp/mailer": "self.version", - "sonsofphp/filesystem-aws": "self.version", - "sonsofphp/filesystem-liip-imagine": "self.version", + "sonsofphp/registry": "self.version", + "sonsofphp/registry-contract": "self.version", "sonsofphp/state-machine": "self.version", "sonsofphp/state-machine-contract": "self.version", - "sonsofphp/assert": "self.version", - "sonsofphp/registry": "self.version", - "sonsofphp/registry-contract": "self.version" + "sonsofphp/version": "self.version", + "sonsofphp/version-contract": "self.version" }, "autoload": { - "psr-4": { - "SonsOfPHP\\Bard\\": "src/SonsOfPHP/Bard/src", - "SonsOfPHP\\Component\\Assert\\": "src/SonsOfPHP/Component/Assert", - "SonsOfPHP\\Component\\StateMachine\\": "src/SonsOfPHP/Component/StateMachine", - "SonsOfPHP\\Contract\\StateMachine\\": "src/SonsOfPHP/Contract/StateMachine", - "SonsOfPHP\\Contract\\Mailer\\": "src/SonsOfPHP/Contract/Mailer", - "SonsOfPHP\\Component\\Mailer\\": "src/SonsOfPHP/Component/Mailer", - "SonsOfPHP\\Component\\Cache\\": "src/SonsOfPHP/Component/Cache", - "SonsOfPHP\\Component\\Clock\\": "src/SonsOfPHP/Component/Clock", - "SonsOfPHP\\Component\\Container\\": "src/SonsOfPHP/Component/Container", - "SonsOfPHP\\Component\\Cookie\\": "src/SonsOfPHP/Component/Cookie", - "SonsOfPHP\\Component\\Cqrs\\": "src/SonsOfPHP/Component/Cqrs", - "SonsOfPHP\\Bundle\\Cqrs\\": "src/SonsOfPHP/Bundle/Cqrs", - "SonsOfPHP\\Bridge\\Symfony\\Cqrs\\": "src/SonsOfPHP/Bridge/Symfony/Cqrs", - "SonsOfPHP\\Bridge\\Symfony\\EventSourcing\\": "src/SonsOfPHP/Bridge/Symfony/EventSourcing", - "SonsOfPHP\\Bridge\\Twig\\Money\\": "src/SonsOfPHP/Bridge/Twig/Money", - "SonsOfPHP\\Component\\EventDispatcher\\": "src/SonsOfPHP/Component/EventDispatcher", - "SonsOfPHP\\Component\\EventSourcing\\": "src/SonsOfPHP/Component/EventSourcing", - "SonsOfPHP\\Bridge\\Doctrine\\EventSourcing\\": "src/SonsOfPHP/Bridge/Doctrine/EventSourcing", - "SonsOfPHP\\Component\\FeatureToggle\\": "src/SonsOfPHP/Component/FeatureToggle", - "SonsOfPHP\\Contract\\Filesystem\\": "src/SonsOfPHP/Contract/Filesystem", - "SonsOfPHP\\Component\\Filesystem\\": "src/SonsOfPHP/Component/Filesystem", - "SonsOfPHP\\Bridge\\Aws\\Filesystem\\": "src/SonsOfPHP/Bridge/Aws/Filesystem", - "SonsOfPHP\\Bridge\\LiipImagine\\Filesystem\\": "src/SonsOfPHP/Bridge/LiipImagine/Filesystem", - "SonsOfPHP\\Component\\HttpFactory\\": "src/SonsOfPHP/Component/HttpFactory", - "SonsOfPHP\\Component\\HttpHandler\\": "src/SonsOfPHP/Component/HttpHandler", - "SonsOfPHP\\Contract\\HttpHandler\\": "src/SonsOfPHP/Contract/HttpHandler", - "SonsOfPHP\\Component\\HttpMessage\\": "src/SonsOfPHP/Component/HttpMessage", - "SonsOfPHP\\Component\\Json\\": "src/SonsOfPHP/Component/Json", - "SonsOfPHP\\Component\\Link\\": "src/SonsOfPHP/Component/Link", - "SonsOfPHP\\Component\\Logger\\": "src/SonsOfPHP/Component/Logger", - "SonsOfPHP\\Component\\Money\\": "src/SonsOfPHP/Component/Money", - "SonsOfPHP\\Component\\Pager\\": "src/SonsOfPHP/Component/Pager", - "SonsOfPHP\\Bridge\\Doctrine\\Collections\\Pager\\": "src/SonsOfPHP/Bridge/Doctrine/Collections/Pager", - "SonsOfPHP\\Bridge\\Doctrine\\DBAL\\Pager\\": "src/SonsOfPHP/Bridge/Doctrine/DBAL/Pager", - "SonsOfPHP\\Bridge\\Doctrine\\ORM\\Pager\\": "src/SonsOfPHP/Bridge/Doctrine/ORM/Pager", - "SonsOfPHP\\Component\\Version\\": "src/SonsOfPHP/Component/Version", - "SonsOfPHP\\Contract\\Common\\": "src/SonsOfPHP/Contract/Common", - "SonsOfPHP\\Contract\\Cookie\\": "src/SonsOfPHP/Contract/Cookie", - "SonsOfPHP\\Contract\\Cqrs\\": "src/SonsOfPHP/Contract/Cqrs", - "SonsOfPHP\\Contract\\EventSourcing\\": "src/SonsOfPHP/Contract/EventSourcing", - "SonsOfPHP\\Contract\\FeatureToggle\\": "src/SonsOfPHP/Contract/FeatureToggle", - "SonsOfPHP\\Contract\\Logger\\": "src/SonsOfPHP/Contract/Logger", - "SonsOfPHP\\Contract\\Money\\": "src/SonsOfPHP/Contract/Money", - "SonsOfPHP\\Contract\\Pager\\": "src/SonsOfPHP/Contract/Pager", - "SonsOfPHP\\Component\\Registry\\": "src/SonsOfPHP/Component/Registry", - "SonsOfPHP\\Contract\\Registry\\": "src/SonsOfPHP/Contract/Registry", - "SonsOfPHP\\Contract\\Version\\": "src/SonsOfPHP/Contract/Version" - }, "exclude-from-classmap": [ "src/SonsOfPHP/Bard/Tests", "src/SonsOfPHP/Component/Assert/Tests", @@ -224,7 +192,56 @@ "src/SonsOfPHP/Bridge/Doctrine/ORM/Pager/Tests", "src/SonsOfPHP/Component/Version/Tests", "src/SonsOfPHP/Component/Registry/Tests" - ] + ], + "psr-4": { + "SonsOfPHP\\Bard\\": "src/SonsOfPHP/Bard/src", + "SonsOfPHP\\Bridge\\Aws\\Filesystem\\": "src/SonsOfPHP/Bridge/Aws/Filesystem", + "SonsOfPHP\\Bridge\\Doctrine\\Collections\\Pager\\": "src/SonsOfPHP/Bridge/Doctrine/Collections/Pager", + "SonsOfPHP\\Bridge\\Doctrine\\DBAL\\Pager\\": "src/SonsOfPHP/Bridge/Doctrine/DBAL/Pager", + "SonsOfPHP\\Bridge\\Doctrine\\EventSourcing\\": "src/SonsOfPHP/Bridge/Doctrine/EventSourcing", + "SonsOfPHP\\Bridge\\Doctrine\\ORM\\Pager\\": "src/SonsOfPHP/Bridge/Doctrine/ORM/Pager", + "SonsOfPHP\\Bridge\\LiipImagine\\Filesystem\\": "src/SonsOfPHP/Bridge/LiipImagine/Filesystem", + "SonsOfPHP\\Bridge\\Symfony\\Cqrs\\": "src/SonsOfPHP/Bridge/Symfony/Cqrs", + "SonsOfPHP\\Bridge\\Symfony\\EventSourcing\\": "src/SonsOfPHP/Bridge/Symfony/EventSourcing", + "SonsOfPHP\\Bridge\\Twig\\Money\\": "src/SonsOfPHP/Bridge/Twig/Money", + "SonsOfPHP\\Bundle\\Cqrs\\": "src/SonsOfPHP/Bundle/Cqrs", + "SonsOfPHP\\Component\\Assert\\": "src/SonsOfPHP/Component/Assert", + "SonsOfPHP\\Component\\Cache\\": "src/SonsOfPHP/Component/Cache", + "SonsOfPHP\\Component\\Clock\\": "src/SonsOfPHP/Component/Clock", + "SonsOfPHP\\Component\\Container\\": "src/SonsOfPHP/Component/Container", + "SonsOfPHP\\Component\\Cookie\\": "src/SonsOfPHP/Component/Cookie", + "SonsOfPHP\\Component\\Cqrs\\": "src/SonsOfPHP/Component/Cqrs", + "SonsOfPHP\\Component\\EventDispatcher\\": "src/SonsOfPHP/Component/EventDispatcher", + "SonsOfPHP\\Component\\EventSourcing\\": "src/SonsOfPHP/Component/EventSourcing", + "SonsOfPHP\\Component\\FeatureToggle\\": "src/SonsOfPHP/Component/FeatureToggle", + "SonsOfPHP\\Component\\Filesystem\\": "src/SonsOfPHP/Component/Filesystem", + "SonsOfPHP\\Component\\HttpFactory\\": "src/SonsOfPHP/Component/HttpFactory", + "SonsOfPHP\\Component\\HttpHandler\\": "src/SonsOfPHP/Component/HttpHandler", + "SonsOfPHP\\Component\\HttpMessage\\": "src/SonsOfPHP/Component/HttpMessage", + "SonsOfPHP\\Component\\Json\\": "src/SonsOfPHP/Component/Json", + "SonsOfPHP\\Component\\Link\\": "src/SonsOfPHP/Component/Link", + "SonsOfPHP\\Component\\Logger\\": "src/SonsOfPHP/Component/Logger", + "SonsOfPHP\\Component\\Mailer\\": "src/SonsOfPHP/Component/Mailer", + "SonsOfPHP\\Component\\Money\\": "src/SonsOfPHP/Component/Money", + "SonsOfPHP\\Component\\Pager\\": "src/SonsOfPHP/Component/Pager", + "SonsOfPHP\\Component\\Registry\\": "src/SonsOfPHP/Component/Registry", + "SonsOfPHP\\Component\\StateMachine\\": "src/SonsOfPHP/Component/StateMachine", + "SonsOfPHP\\Component\\Version\\": "src/SonsOfPHP/Component/Version", + "SonsOfPHP\\Contract\\Common\\": "src/SonsOfPHP/Contract/Common", + "SonsOfPHP\\Contract\\Cookie\\": "src/SonsOfPHP/Contract/Cookie", + "SonsOfPHP\\Contract\\Cqrs\\": "src/SonsOfPHP/Contract/Cqrs", + "SonsOfPHP\\Contract\\EventSourcing\\": "src/SonsOfPHP/Contract/EventSourcing", + "SonsOfPHP\\Contract\\FeatureToggle\\": "src/SonsOfPHP/Contract/FeatureToggle", + "SonsOfPHP\\Contract\\Filesystem\\": "src/SonsOfPHP/Contract/Filesystem", + "SonsOfPHP\\Contract\\HttpHandler\\": "src/SonsOfPHP/Contract/HttpHandler", + "SonsOfPHP\\Contract\\Logger\\": "src/SonsOfPHP/Contract/Logger", + "SonsOfPHP\\Contract\\Mailer\\": "src/SonsOfPHP/Contract/Mailer", + "SonsOfPHP\\Contract\\Money\\": "src/SonsOfPHP/Contract/Money", + "SonsOfPHP\\Contract\\Pager\\": "src/SonsOfPHP/Contract/Pager", + "SonsOfPHP\\Contract\\Registry\\": "src/SonsOfPHP/Contract/Registry", + "SonsOfPHP\\Contract\\StateMachine\\": "src/SonsOfPHP/Contract/StateMachine", + "SonsOfPHP\\Contract\\Version\\": "src/SonsOfPHP/Contract/Version" + } }, "extra": { "sort-packages": true, @@ -233,17 +250,16 @@ } }, "require-dev": { + "phpunit/phpunit": "^10.4", + "sonsofphp/filesystem": "0.3.x-dev", "symfony/http-foundation": "^5 || ^6 || ^7", - "symfony/serializer": "^5 || ^6 || ^7", - "symfony/phpunit-bridge": "^6 || ^7", - "symfony/error-handler": "^6", - "phpunit/phpunit": "^10.4" + "symfony/serializer": "^5 || ^6 || ^7" }, "autoload-dev": { "psr-4": { "SonsOfPHP\\Bard\\Tests\\": "src/SonsOfPHP/Bard/Tests", - "SonsOfPHP\\Bundle\\Cqrs\\Tests\\": "src/SonsOfPHP/Bundle/Cqrs/Tests", - "SonsOfPHP\\Bridge\\Symfony\\Cqrs\\Tests\\": "src/SonsOfPHP/Bridge/Symfony/Cqrs/Tests" + "SonsOfPHP\\Bridge\\Symfony\\Cqrs\\Tests\\": "src/SonsOfPHP/Bridge/Symfony/Cqrs/Tests", + "SonsOfPHP\\Bundle\\Cqrs\\Tests\\": "src/SonsOfPHP/Bundle/Cqrs/Tests" } } -} +} \ No newline at end of file diff --git a/src/SonsOfPHP/Bard/dist/.gitignore b/src/SonsOfPHP/Bard/dist/.gitignore new file mode 100644 index 00000000..86d84656 --- /dev/null +++ b/src/SonsOfPHP/Bard/dist/.gitignore @@ -0,0 +1 @@ +*.phar diff --git a/src/SonsOfPHP/Bard/src/Console/Command/MergeCommand.php b/src/SonsOfPHP/Bard/src/Console/Command/MergeCommand.php index 361863e1..fbda5c42 100644 --- a/src/SonsOfPHP/Bard/src/Console/Command/MergeCommand.php +++ b/src/SonsOfPHP/Bard/src/Console/Command/MergeCommand.php @@ -10,13 +10,13 @@ use SonsOfPHP\Bard\Worker\File\Composer\Package\BranchAlias; use SonsOfPHP\Bard\Worker\File\Composer\Package\Funding; use SonsOfPHP\Bard\Worker\File\Composer\Package\Support; +use SonsOfPHP\Bard\Worker\File\Composer\Root\ClearSection; use SonsOfPHP\Bard\Worker\File\Composer\Root\UpdateAutoloadDevSection; use SonsOfPHP\Bard\Worker\File\Composer\Root\UpdateAutoloadSection; use SonsOfPHP\Bard\Worker\File\Composer\Root\UpdateProvideSection; use SonsOfPHP\Bard\Worker\File\Composer\Root\UpdateReplaceSection; use SonsOfPHP\Bard\Worker\File\Composer\Root\UpdateRequireDevSection; use SonsOfPHP\Bard\Worker\File\Composer\Root\UpdateRequireSection; -use SonsOfPHP\Component\Json\Json; use Symfony\Component\Console\Helper\HelperInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -31,21 +31,12 @@ */ final class MergeCommand extends AbstractCommand { - private readonly Json $json; - - private array $bardConfig; + private JsonFile $bardConfig; private string $mainComposerFile; private ?HelperInterface $formatter = null; - public function __construct() - { - $this->json = new Json(); - - parent::__construct(); - } - protected function configure(): void { $this @@ -63,9 +54,7 @@ protected function initialize(InputInterface $input, OutputInterface $output): v throw new RuntimeException(sprintf('"%s" file does not exist', $bardConfigFile)); } - $this->bardConfig = $this->json->getDecoder() - ->objectAsArray() - ->decode(file_get_contents($bardConfigFile)); + $this->bardConfig = new JsonFile($bardConfigFile); $this->mainComposerFile = $input->getOption('working-dir') . '/composer.json'; if (!file_exists($this->mainComposerFile)) { @@ -83,10 +72,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int $rootComposerJsonFile = new JsonFile($input->getOption('working-dir') . '/composer.json'); // Clean out a few of the sections in root composer.json file - $rootComposerJsonFile = $rootComposerJsonFile->setSection('autoload', []); - $rootComposerJsonFile = $rootComposerJsonFile->setSection('autoload-dev', []); - - foreach ($this->bardConfig['packages'] as $pkg) { + $rootComposerJsonFile = $rootComposerJsonFile->with(new ClearSection('autoload')); + $rootComposerJsonFile = $rootComposerJsonFile->with(new ClearSection('autoload-dev')); + $rootComposerJsonFile = $rootComposerJsonFile->with(new ClearSection('require')); + $rootComposerJsonFile = $rootComposerJsonFile->with(new ClearSection('require-dev')); + $rootComposerJsonFile = $rootComposerJsonFile->with(new ClearSection('replace')); + $rootComposerJsonFile = $rootComposerJsonFile->with(new ClearSection('provide')); + + foreach ($this->bardConfig->getSection('packages') as $pkg) { $pkgComposerFile = realpath($input->getOption('working-dir') . '/' . $pkg['path'] . '/composer.json'); if (!file_exists($pkgComposerFile)) { $output->writeln(sprintf('No "%s" found, skipping', $packageComposerFile)); diff --git a/src/SonsOfPHP/Bard/src/JsonFile.php b/src/SonsOfPHP/Bard/src/JsonFile.php index 4f8e20cb..923eeaf3 100644 --- a/src/SonsOfPHP/Bard/src/JsonFile.php +++ b/src/SonsOfPHP/Bard/src/JsonFile.php @@ -4,8 +4,6 @@ namespace SonsOfPHP\Bard; -use SonsOfPHP\Component\Json\Json; - /** * Used to manage bard.json and composer.json files * @@ -15,20 +13,13 @@ final class JsonFile { private array $config = []; - private Json $json; - public function __construct( private string $filename, - ) { - $this->json = new Json(); - $this->load(); - } + ) {} private function load(): void { - $this->config = $this->json->getDecoder() - ->objectAsArray() - ->decode(file_get_contents($this->filename)); + $this->config = json_decode(file_get_contents($this->filename), true); } public function getFilename(): string @@ -43,7 +34,7 @@ public function getFilename(): string */ public function getSection(string $section): mixed { - if (!isset($this->config)) { + if ([] === $this->config) { $this->load(); } @@ -54,7 +45,7 @@ public function getSection(string $section): mixed */ public function setSection(string $section, $value): self { - if (!isset($this->config)) { + if ([] === $this->config) { $this->load(); } @@ -64,19 +55,12 @@ public function setSection(string $section, $value): self return $clone; } - /** - */ public function toJson(): string { - return $this->json->getEncoder() - ->prettyPrint() - ->unescapedUnicode() - ->unescapedSlashes() - ->encode($this->config); + return json_encode($this->config, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); } /** - * $operator = new Operator(); * $jsonFile->with(new ExampleOperator()); */ public function with($operator): self diff --git a/src/SonsOfPHP/Bard/src/Worker/File/Composer/Package/Support.php b/src/SonsOfPHP/Bard/src/Worker/File/Composer/Package/Support.php index 1c20196a..5860ce6f 100644 --- a/src/SonsOfPHP/Bard/src/Worker/File/Composer/Package/Support.php +++ b/src/SonsOfPHP/Bard/src/Worker/File/Composer/Package/Support.php @@ -17,6 +17,11 @@ public function __construct(private JsonFile $rootComposerJsonFile) {} public function apply(JsonFile $pkgComposerJsonFile): JsonFile { $rootSupportSection = $this->rootComposerJsonFile->getSection('support'); + $pkgSupportSection = $pkgComposerJsonFile->getSection('support'); + + // Docs may be different for package so we do not want to overwrite + // that value + $rootSupportSection['docs'] = $pkgSupportSection['docs']; return $pkgComposerJsonFile->setSection('support', $rootSupportSection); } diff --git a/src/SonsOfPHP/Bard/src/Worker/File/Composer/Root/ClearSection.php b/src/SonsOfPHP/Bard/src/Worker/File/Composer/Root/ClearSection.php new file mode 100644 index 00000000..9708a06a --- /dev/null +++ b/src/SonsOfPHP/Bard/src/Worker/File/Composer/Root/ClearSection.php @@ -0,0 +1,21 @@ + + */ +final readonly class ClearSection implements WorkerInterface +{ + public function __construct(private string $section) {} + + public function apply(JsonFile $rootComposerJsonFile): JsonFile + { + return $rootComposerJsonFile->setSection($this->section, []); + } +} diff --git a/src/SonsOfPHP/Bard/src/Worker/File/Composer/Root/UpdateAutoloadDevSection.php b/src/SonsOfPHP/Bard/src/Worker/File/Composer/Root/UpdateAutoloadDevSection.php index d405186d..1ebbfd4f 100644 --- a/src/SonsOfPHP/Bard/src/Worker/File/Composer/Root/UpdateAutoloadDevSection.php +++ b/src/SonsOfPHP/Bard/src/Worker/File/Composer/Root/UpdateAutoloadDevSection.php @@ -43,12 +43,16 @@ public function apply(JsonFile $rootComposerJsonFile): JsonFile if (isset($rootAutoloadSection['psr-4'])) { $rootAutoloadSection['psr-4'] = array_unique($rootAutoloadSection['psr-4']); + ksort($rootAutoloadSection['psr-4']); } if (isset($rootAutoloadSection['exclude-from-classmap'])) { $rootAutoloadSection['exclude-from-classmap'] = array_unique($rootAutoloadSection['exclude-from-classmap']); + ksort($rootAutoloadSection['exclude-from-classmap']); } + ksort($rootAutoloadSection); + return $rootComposerJsonFile->setSection('autoload-dev', $rootAutoloadSection); } } diff --git a/src/SonsOfPHP/Bard/src/Worker/File/Composer/Root/UpdateAutoloadSection.php b/src/SonsOfPHP/Bard/src/Worker/File/Composer/Root/UpdateAutoloadSection.php index 90329fdf..0af2a253 100644 --- a/src/SonsOfPHP/Bard/src/Worker/File/Composer/Root/UpdateAutoloadSection.php +++ b/src/SonsOfPHP/Bard/src/Worker/File/Composer/Root/UpdateAutoloadSection.php @@ -47,12 +47,16 @@ public function apply(JsonFile $rootComposerJsonFile): JsonFile if (isset($rootAutoloadSection['psr-4'])) { $rootAutoloadSection['psr-4'] = array_unique($rootAutoloadSection['psr-4']); + ksort($rootAutoloadSection['psr-4']); } if (isset($rootAutoloadSection['exclude-from-classmap'])) { $rootAutoloadSection['exclude-from-classmap'] = array_unique($rootAutoloadSection['exclude-from-classmap']); + ksort($rootAutoloadSection['exclude-from-classmap']); } + ksort($rootAutoloadSection); + return $rootComposerJsonFile->setSection('autoload', $rootAutoloadSection); } } diff --git a/src/SonsOfPHP/Bard/src/Worker/File/Composer/Root/UpdateProvideSection.php b/src/SonsOfPHP/Bard/src/Worker/File/Composer/Root/UpdateProvideSection.php index 7169454b..5f18b062 100644 --- a/src/SonsOfPHP/Bard/src/Worker/File/Composer/Root/UpdateProvideSection.php +++ b/src/SonsOfPHP/Bard/src/Worker/File/Composer/Root/UpdateProvideSection.php @@ -27,6 +27,8 @@ public function apply(JsonFile $rootComposerJsonFile): JsonFile $rootProvideSection[$pkg] = $version; } + ksort($rootProvideSection); + return $rootComposerJsonFile->setSection('provide', $rootProvideSection); } } diff --git a/src/SonsOfPHP/Bard/src/Worker/File/Composer/Root/UpdateReplaceSection.php b/src/SonsOfPHP/Bard/src/Worker/File/Composer/Root/UpdateReplaceSection.php index 290dd5ab..ef9deb2f 100644 --- a/src/SonsOfPHP/Bard/src/Worker/File/Composer/Root/UpdateReplaceSection.php +++ b/src/SonsOfPHP/Bard/src/Worker/File/Composer/Root/UpdateReplaceSection.php @@ -20,6 +20,7 @@ public function apply(JsonFile $rootComposerJsonFile): JsonFile $pkgName = $this->pkgComposerJsonFile->getSection('name'); $rootReplace[$pkgName] = 'self.version'; + ksort($rootReplace); return $rootComposerJsonFile->setSection('replace', $rootReplace); } diff --git a/src/SonsOfPHP/Bard/src/Worker/File/Composer/Root/UpdateRequireDevSection.php b/src/SonsOfPHP/Bard/src/Worker/File/Composer/Root/UpdateRequireDevSection.php index b8fb9749..e9b4f907 100644 --- a/src/SonsOfPHP/Bard/src/Worker/File/Composer/Root/UpdateRequireDevSection.php +++ b/src/SonsOfPHP/Bard/src/Worker/File/Composer/Root/UpdateRequireDevSection.php @@ -53,6 +53,8 @@ public function apply(JsonFile $rootComposerJsonFile): JsonFile $rootRequireDev[$package] = $version; } + ksort($rootRequireDev); + return $rootComposerJsonFile->setSection('require-dev', $rootRequireDev); } } diff --git a/src/SonsOfPHP/Bard/src/Worker/File/Composer/Root/UpdateRequireSection.php b/src/SonsOfPHP/Bard/src/Worker/File/Composer/Root/UpdateRequireSection.php index 0b49fcbd..eee2891a 100644 --- a/src/SonsOfPHP/Bard/src/Worker/File/Composer/Root/UpdateRequireSection.php +++ b/src/SonsOfPHP/Bard/src/Worker/File/Composer/Root/UpdateRequireSection.php @@ -35,6 +35,8 @@ public function apply(JsonFile $rootComposerJsonFile): JsonFile $rootRequire[$package] = $version; } + ksort($rootRequire); + return $rootComposerJsonFile->setSection('require', $rootRequire); } } diff --git a/src/SonsOfPHP/Component/Cache/composer.json b/src/SonsOfPHP/Component/Cache/composer.json index 4fbfa0aa..7fb9e02c 100644 --- a/src/SonsOfPHP/Component/Cache/composer.json +++ b/src/SonsOfPHP/Component/Cache/composer.json @@ -64,4 +64,4 @@ "url": "https://tidelift.com/subscription/pkg/packagist-sonsofphp-sonsofphp" } ] -} +} \ No newline at end of file