Skip to content

Commit 43cf67d

Browse files
committed
Merge copnflicts
1 parent 4f57589 commit 43cf67d

7 files changed

+44
-99
lines changed

src/Argument/ArgumentInterface.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,5 @@
66

77
interface ArgumentInterface
88
{
9-
/**
10-
* @return mixed
11-
*/
12-
public function getValue();
9+
public function getValue(): mixed;
1310
}

src/Argument/DefaultValueArgument.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,12 @@
66

77
class DefaultValueArgument extends ResolvableArgument implements DefaultValueInterface
88
{
9-
protected $defaultValue;
10-
11-
public function __construct(string $value, $defaultValue = null)
9+
public function __construct(string $value, protected mixed $defaultValue = null)
1210
{
13-
$this->defaultValue = $defaultValue;
1411
parent::__construct($value);
1512
}
1613

17-
/**
18-
* @return mixed|null
19-
*/
20-
public function getDefaultValue()
14+
public function getDefaultValue(): mixed
2115
{
2216
return $this->defaultValue;
2317
}

src/Argument/DefaultValueInterface.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,5 @@
66

77
interface DefaultValueInterface extends ArgumentInterface
88
{
9-
/**
10-
* @return mixed
11-
*/
12-
public function getDefaultValue();
9+
public function getDefaultValue(): mixed;
1310
}

src/Argument/LiteralArgument.php

+3-9
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@ class LiteralArgument implements LiteralArgumentInterface
1919
public const TYPE_OBJECT = 'object';
2020
public const TYPE_STRING = 'string';
2121

22-
/**
23-
* @var mixed
24-
*/
25-
protected $value;
22+
protected mixed $value;
2623

27-
public function __construct($value, string $type = null)
24+
public function __construct(mixed $value, string $type = null)
2825
{
2926
if (
3027
null === $type
@@ -38,10 +35,7 @@ public function __construct($value, string $type = null)
3835
}
3936
}
4037

41-
/**
42-
* {@inheritdoc}
43-
*/
44-
public function getValue()
38+
public function getValue(): mixed
4539
{
4640
return $this->value;
4741
}

src/Argument/ResolvableArgument.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@
66

77
class ResolvableArgument implements ResolvableArgumentInterface
88
{
9-
protected $value;
10-
11-
public function __construct(string $value)
9+
public function __construct(protected string $value)
1210
{
13-
$this->value = $value;
1411
}
1512

1613
public function getValue(): string

src/Definition/Definition.php

+33-65
Original file line numberDiff line numberDiff line change
@@ -21,55 +21,18 @@ class Definition implements ArgumentResolverInterface, DefinitionInterface
2121
use ArgumentResolverTrait;
2222
use ContainerAwareTrait;
2323

24-
/**
25-
* @var string
26-
*/
27-
protected $alias;
28-
29-
/**
30-
* @var mixed
31-
*/
32-
protected $concrete;
33-
34-
/**
35-
* @var boolean
36-
*/
37-
protected $shared = false;
38-
39-
/**
40-
* @var array
41-
*/
42-
protected $tags = [];
43-
44-
/**
45-
* @var array
46-
*/
47-
protected $arguments = [];
48-
49-
/**
50-
* @var array
51-
*/
52-
protected $methods = [];
53-
54-
/**
55-
* @var mixed
56-
*/
57-
protected $resolved;
58-
59-
/**
60-
* @var bool
61-
*/
62-
protected $isAlreadySearched = false;
63-
64-
/**
65-
* @param string $id
66-
* @param mixed|null $concrete
67-
*/
68-
public function __construct(string $id, $concrete = null)
69-
{
70-
$concrete ??= $id;
71-
$this->alias = $id;
72-
$this->concrete = $concrete;
24+
protected mixed $resolved = null;
25+
protected array $recursiveCheck = [];
26+
27+
public function __construct(
28+
protected string $id,
29+
protected mixed $concrete = null,
30+
protected bool $shared = false,
31+
protected array $arguments = [],
32+
protected array $methods = [],
33+
protected array $tags = [],
34+
) {
35+
$this->concrete ??= $this->id;
7336
}
7437

7538
public function addTag(string $tag): DefinitionInterface
@@ -83,15 +46,25 @@ public function hasTag(string $tag): bool
8346
return isset($this->tags[$tag]);
8447
}
8548

86-
public function setAlias(string $id): DefinitionInterface
49+
public function setId(string $id): DefinitionInterface
8750
{
88-
$this->alias = $id;
51+
$this->id = $id;
8952
return $this;
9053
}
9154

55+
public function getId(): string
56+
{
57+
return $this->id;
58+
}
59+
60+
public function setAlias(string $id): DefinitionInterface
61+
{
62+
return $this->setId($id);
63+
}
64+
9265
public function getAlias(): string
9366
{
94-
return $this->alias;
67+
return $this->getId();
9568
}
9669

9770
public function setShared(bool $shared = true): DefinitionInterface
@@ -135,7 +108,7 @@ public function addArguments(array $args): DefinitionInterface
135108
public function addMethodCall(string $method, array $args = []): DefinitionInterface
136109
{
137110
$this->methods[] = [
138-
'method' => $method,
111+
'method' => $method,
139112
'arguments' => $args
140113
];
141114

@@ -151,7 +124,7 @@ public function addMethodCalls(array $methods = []): DefinitionInterface
151124
return $this;
152125
}
153126

154-
public function resolve()
127+
public function resolve(): mixed
155128
{
156129
if (null !== $this->resolved && $this->isShared()) {
157130
return $this->resolved;
@@ -160,7 +133,7 @@ public function resolve()
160133
return $this->resolveNew();
161134
}
162135

163-
public function resolveNew()
136+
public function resolveNew(): mixed
164137
{
165138
$concrete = $this->concrete;
166139

@@ -192,28 +165,23 @@ public function resolveNew()
192165
}
193166

194167
// stop recursive resolving
195-
if ($this->isAlreadySearched) {
196-
throw new NotFoundException(
197-
sprintf('Alias or class "%s" did not found.', $concrete)
198-
);
168+
if (is_string($concrete) && in_array($concrete, $this->recursiveCheck)) {
169+
$this->resolved = $concrete;
170+
return $concrete;
199171
}
200172

201173
// if we still have a string, try to pull it from the container
202174
// this allows for `alias -> alias -> ... -> concrete
203175
if (is_string($concrete) && $container instanceof ContainerInterface && $container->has($concrete)) {
204-
$this->isAlreadySearched = true;
176+
$this->recursiveCheck[] = $concrete;
205177
$concrete = $container->get($concrete);
206178
}
207179

208180
$this->resolved = $concrete;
209181
return $concrete;
210182
}
211183

212-
/**
213-
* @param callable $concrete
214-
* @return mixed
215-
*/
216-
protected function resolveCallable(callable $concrete)
184+
protected function resolveCallable(callable $concrete): mixed
217185
{
218186
$resolved = $this->resolveArguments($this->arguments);
219187
return call_user_func_array($concrete, $resolved);

tests/ContainerTest.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,12 @@ public function testContainerAwareCannotBeUsedWithoutImplementingInterface(): vo
222222
$class->setContainer($container);
223223
}
224224

225-
public function testNonExistentClassCausesException(): void
225+
public function testNonExistentClassResolvesAsString(): void
226226
{
227227
$container = new Container();
228228
$container->add(NonExistent::class);
229229

230-
self::assertTrue($container->has(NonExistent::class));
231-
232-
$this->expectException(NotFoundException::class);
233-
$container->get(NonExistent::class);
230+
$this->assertTrue($container->has(NonExistent::class));
231+
$this->assertSame(NonExistent::class, $container->get(NonExistent::class));
234232
}
235233
}

0 commit comments

Comments
 (0)