diff --git a/config/config.php b/config/config.php index f5ae006ec1..2fdb38eaeb 100644 --- a/config/config.php +++ b/config/config.php @@ -46,6 +46,8 @@ ComposerJsonSection::HOMEPAGE, ComposerJsonSection::LICENSE, ComposerJsonSection::AUTHORS, + ComposerJsonSection::SUPPORT, + ComposerJsonSection::FUNDING, ComposerJsonSection::BIN, ComposerJsonSection::REQUIRE, ComposerJsonSection::REQUIRE_DEV, diff --git a/packages-tests/ComposerJsonManipulator/ComposerJsonFactory/Source/full_composer.json b/packages-tests/ComposerJsonManipulator/ComposerJsonFactory/Source/full_composer.json index f560214b37..10eb0e10c7 100644 --- a/packages-tests/ComposerJsonManipulator/ComposerJsonFactory/Source/full_composer.json +++ b/packages-tests/ComposerJsonManipulator/ComposerJsonFactory/Source/full_composer.json @@ -7,6 +7,16 @@ "require": { "php": ">=7.3" }, + "support": { + "email": "support@example.org", + "irc": "irc://irc.freenode.org/example" + }, + "funding": [ + { + "type": "example", + "url": "https://www.patreon.com/example" + } + ], "require-dev": { "phpunit/phpunit": "^8.5|^9.4" }, diff --git a/packages/ComposerJsonManipulator/ComposerJsonFactory.php b/packages/ComposerJsonManipulator/ComposerJsonFactory.php index 3e9fc26166..65d40876bc 100644 --- a/packages/ComposerJsonManipulator/ComposerJsonFactory.php +++ b/packages/ComposerJsonManipulator/ComposerJsonFactory.php @@ -156,6 +156,14 @@ public function createFromArray(array $jsonArray): ComposerJson $composerJson->setProvide($jsonArray[ComposerJsonSection::PROVIDE]); } + if (isset($jsonArray[ComposerJsonSection::FUNDING])) { + $composerJson->setFunding($jsonArray[ComposerJsonSection::FUNDING]); + } + + if (isset($jsonArray[ComposerJsonSection::SUPPORT])) { + $composerJson->setSupport($jsonArray[ComposerJsonSection::SUPPORT]); + } + $orderedKeys = array_keys($jsonArray); $composerJson->setOrderedKeys($orderedKeys); diff --git a/packages/ComposerJsonManipulator/ValueObject/ComposerJson.php b/packages/ComposerJsonManipulator/ValueObject/ComposerJson.php index e87a3e684f..3b65426613 100644 --- a/packages/ComposerJsonManipulator/ValueObject/ComposerJson.php +++ b/packages/ComposerJsonManipulator/ValueObject/ComposerJson.php @@ -66,6 +66,16 @@ final class ComposerJson */ private array $extra = []; + /** + * @var mixed[] + */ + private array $funding = []; + + /** + * @var mixed[] + */ + private array $support = []; + /** * @var array */ @@ -336,6 +346,38 @@ public function setExtra(array $extra): void $this->extra = $extra; } + /** + * @return mixed[] + */ + public function getFunding(): array + { + return $this->funding; + } + + /** + * @param mixed[] $funding + */ + public function setFunding(array $funding): void + { + $this->funding = $funding; + } + + /** + * @return mixed[] + */ + public function getSupport(): array + { + return $this->support; + } + + /** + * @param mixed[] $support + */ + public function setSupport(array $support): void + { + $this->support = $support; + } + public function getName(): ?string { return $this->name; @@ -416,6 +458,8 @@ public function getJsonArray(): array ComposerJsonSection::CONFLICT => $this->conflicts, ComposerJsonSection::PROVIDE => $this->provide, ComposerJsonSection::VERSION => $this->version, + ComposerJsonSection::FUNDING => $this->funding, + ComposerJsonSection::SUPPORT => $this->support, ]); if ($this->minimumStability !== null) { diff --git a/packages/ComposerJsonManipulator/ValueObject/ComposerJsonSection.php b/packages/ComposerJsonManipulator/ValueObject/ComposerJsonSection.php index fc05d17576..81c8ee8ae0 100644 --- a/packages/ComposerJsonManipulator/ValueObject/ComposerJsonSection.php +++ b/packages/ComposerJsonManipulator/ValueObject/ComposerJsonSection.php @@ -129,4 +129,14 @@ final class ComposerJsonSection * @var string */ public const VERSION = 'version'; + + /** + * @var string + */ + public const FUNDING = 'funding'; + + /** + * @var string + */ + public const SUPPORT = 'support'; } diff --git a/phpunit.xml b/phpunit.xml index 6abd409638..042a5db575 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -2,6 +2,6 @@ tests - packages/*/tests + packages-tests