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\Dependency;
use Innmind\Compose\{
Definition\Name,
Services,
Exception\ArgumentNotProvided,
Exception\ArgumentNotDefined
};
use Innmind\Immutable\Str;
final class Argument
{
private $name;
private $value;
private $reference;
private function __construct(Name $name)
$this->name = $name;
}
public static function fromValue(Name $name, $value): self
if (!is_string($value)) {
$self = new self($name);
$self->value = $value;
return $self;
$value = Str::of($value);
if ((string) $value->substring(0, 1) !== '$') {
$self->value = (string) $value;
$self->reference = new Name((string) $value->substring(1));
public function name(): Name
return $this->name;
public function resolve(Services $services)
if (!$this->reference instanceof Name) {
return $this->value;
try {
return $services->arguments()->get($this->reference);
} catch (ArgumentNotProvided $e) {
if ($e->argument()->hasDefault()) {
return $services->build($e->argument()->default());
if ($e->argument()->optional()) {
return null;
throw $e;
} catch (ArgumentNotDefined $e) {
//pass
// todo: allow to resolve services from other dependencies
return $services->build($this->reference);