Skip to content

Commit

Permalink
Add support/funding sections
Browse files Browse the repository at this point in the history
  • Loading branch information
mrook committed Nov 11, 2023
1 parent a8f1ca0 commit d28635d
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 1 deletion.
2 changes: 2 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
ComposerJsonSection::HOMEPAGE,
ComposerJsonSection::LICENSE,
ComposerJsonSection::AUTHORS,
ComposerJsonSection::SUPPORT,
ComposerJsonSection::FUNDING,
ComposerJsonSection::BIN,
ComposerJsonSection::REQUIRE,
ComposerJsonSection::REQUIRE_DEV,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
8 changes: 8 additions & 0 deletions packages/ComposerJsonManipulator/ComposerJsonFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
44 changes: 44 additions & 0 deletions packages/ComposerJsonManipulator/ValueObject/ComposerJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ final class ComposerJson
*/
private array $extra = [];

/**
* @var mixed[]
*/
private array $funding = [];

/**
* @var mixed[]
*/
private array $support = [];

/**
* @var array<string, string>
*/
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" cacheDirectory=".phpunit.cache">
<testsuite name="all">
<directory>tests</directory>
<directory>packages/*/tests</directory>
<directory>packages-tests</directory>
</testsuite>
</phpunit>

0 comments on commit d28635d

Please sign in to comment.