diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-06 20:04:25 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-06 20:04:25 +0900 |
| commit | 3f525f228052ad04e6f9da6ff160bef803d079bd (patch) | |
| tree | 3fe2d078e6a30b12ce041b1b3f1e589bc47cf8f3 /crates/shirabe/tests/plugin/fixtures/values-v1 | |
| parent | d9dca94603766712b5989ea8169c9e286d27a60c (diff) | |
| download | php-shirabe-3f525f228052ad04e6f9da6ff160bef803d079bd.tar.gz php-shirabe-3f525f228052ad04e6f9da6ff160bef803d079bd.tar.zst php-shirabe-3f525f228052ad04e6f9da6ff160bef803d079bd.zip | |
feat(plugin): let links and release dates cross the RPC boundary
The link getters and setters and the release date accessors were explicit
errors for every non-empty value, because an immutable value has no entity
to point a handle at. They now cross as materialized values: the descriptor
names the real class and the constructor arguments, and each side builds a
genuine instance of its own.
The semver constraint a link holds is encoded structurally rather than
re-parsed from its string form, so the pretty strings and the conjunctive
flag survive the crossing.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/tests/plugin/fixtures/values-v1')
| -rw-r--r-- | crates/shirabe/tests/plugin/fixtures/values-v1/Values/Plugin.php | 85 | ||||
| -rw-r--r-- | crates/shirabe/tests/plugin/fixtures/values-v1/composer.json | 12 |
2 files changed, 97 insertions, 0 deletions
diff --git a/crates/shirabe/tests/plugin/fixtures/values-v1/Values/Plugin.php b/crates/shirabe/tests/plugin/fixtures/values-v1/Values/Plugin.php new file mode 100644 index 00000000..685aa903 --- /dev/null +++ b/crates/shirabe/tests/plugin/fixtures/values-v1/Values/Plugin.php @@ -0,0 +1,85 @@ +<?php + +namespace Values; + +use Composer\Composer; +use Composer\IO\IOInterface; +use Composer\Package\Link; +use Composer\Plugin\PluginInterface; +use Composer\Semver\Constraint\Constraint; +use Composer\Semver\Constraint\ConstraintInterface; +use Composer\Semver\Constraint\MatchAllConstraint; +use Composer\Semver\Constraint\MatchNoneConstraint; +use Composer\Semver\Constraint\MultiConstraint; + +class Plugin implements PluginInterface +{ + public function activate(Composer $composer, IOInterface $io) + { + $package = $composer->getPackage(); + + foreach ($package->getRequires() as $name => $link) { + if (!$link instanceof Link) { + throw new \RuntimeException('not a Link: ' . get_class($link)); + } + $io->write(sprintf( + '%s | %s | %s | %s | %s | %s', + $name, + $link->getSource(), + $link->getTarget(), + $link->getDescription(), + $link->getPrettyConstraint(), + self::render($link->getConstraint()) + )); + } + + $package->setRequires([ + 'bar/plain' => new Link('dummy/root', 'bar/plain', self::pretty(new Constraint('==', '2.0.0.0'), '2.0'), Link::TYPE_REQUIRE, '2.0'), + 'bar/multi' => new Link('dummy/root', 'bar/multi', new MultiConstraint([ + new Constraint('<', '1.0.0.0'), + new Constraint('>=', '3.0.0.0'), + ], false), Link::TYPE_DEV_REQUIRE, '<1.0 || >=3.0'), + 'bar/all' => new Link('dummy/root', 'bar/all', new MatchAllConstraint(), Link::TYPE_REQUIRE, '*'), + 'bar/none' => new Link('dummy/root', 'bar/none', self::pretty(new MatchNoneConstraint(), 'nothing'), Link::TYPE_REQUIRE, ''), + ]); + + $package->setReleaseDate(new \DateTimeImmutable('2024-03-04 05:06:07.123456', new \DateTimeZone('Asia/Tokyo'))); + $io->write('release date: ' . $package->getReleaseDate()->format('Y-m-d\TH:i:s.uP')); + } + + public function deactivate(Composer $composer, IOInterface $io) + { + } + + public function uninstall(Composer $composer, IOInterface $io) + { + } + + private static function pretty(ConstraintInterface $constraint, string $prettyString): ConstraintInterface + { + $constraint->setPrettyString($prettyString); + + return $constraint; + } + + private static function render(ConstraintInterface $constraint): string + { + if ($constraint instanceof Constraint) { + $shape = sprintf('Constraint(%s %s)', $constraint->getOperator(), $constraint->getVersion()); + } elseif ($constraint instanceof MultiConstraint) { + $shape = sprintf( + 'MultiConstraint(%s: %s)', + $constraint->isConjunctive() ? 'and' : 'or', + implode(', ', array_map([self::class, 'render'], $constraint->getConstraints())) + ); + } elseif ($constraint instanceof MatchAllConstraint) { + $shape = 'MatchAllConstraint()'; + } elseif ($constraint instanceof MatchNoneConstraint) { + $shape = 'MatchNoneConstraint()'; + } else { + throw new \RuntimeException('unexpected constraint: ' . get_class($constraint)); + } + + return $shape . ' pretty=' . $constraint->getPrettyString(); + } +} diff --git a/crates/shirabe/tests/plugin/fixtures/values-v1/composer.json b/crates/shirabe/tests/plugin/fixtures/values-v1/composer.json new file mode 100644 index 00000000..d4e5861e --- /dev/null +++ b/crates/shirabe/tests/plugin/fixtures/values-v1/composer.json @@ -0,0 +1,12 @@ +{ + "name": "values-v1", + "version": "1.0.0", + "type": "composer-plugin", + "autoload": { "psr-0": { "Values": "" } }, + "extra": { + "class": "Values\\Plugin" + }, + "require": { + "composer-plugin-api": "^2.0" + } +} |
