for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types = 1);
namespace Innmind\Compose\Definition\Service\Argument;
use Innmind\Compose\{
Definition\Service\Argument,
Definition\Service\Arguments,
Definitions,
Exception\ValueNotSupported,
Exception\LogicException
};
use Innmind\Immutable\{
Pair as ImmutablePair,
StreamInterface,
Str
final class Pair implements Argument
{
private $key;
private $value;
private function __construct(Argument $key, Argument $value)
if ($key instanceof Unwind || $value instanceof Unwind) {
throw new LogicException;
}
$this->key = $key;
$this->value = $value;
/**
* {@inheritdoc}
*/
public static function fromValue($value, Arguments $arguments): Argument
if (!is_string($value)) {
throw new ValueNotSupported;
$value = Str::of($value);
if (!$value->matches('~^<\S+, ?\S+>$~')) {
throw new ValueNotSupported((string) $value);
$components = $value->capture('~^<(?<key>\S+), ?(?<value>\S+)>$~');
return new self(
$arguments->load((string) $components->get('key')),
$arguments->load((string) $components->get('value'))
);
public function resolve(
StreamInterface $built,
Definitions $definitions
): StreamInterface {
$key = $this
->key
->resolve(
$built->clear(),
$definitions
)
->current();
$value = $this
->value
return $built->add(new ImmutablePair($key, $value));