Issues (94)

src/di/Untarget.php (2 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\Di;
6
7
use Ray\Aop\ReflectionClass;
8
9
final class Untarget
10
{
11
    /**
12
     * @phpstan-var ReflectionClass<object>
13
     * @psalm-var ReflectionClass
14
     */
15
    private readonly ReflectionClass $class;
16
    private string $scope = Scope::PROTOTYPE;
17
18
    /**
19
     * @param class-string $class
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string.
Loading history...
20
     */
21
    public function __construct(string $class)
22
    {
23
        $this->class = new ReflectionClass($class);
0 ignored issues
show
The property class is declared read-only in Ray\Di\Untarget.
Loading history...
24
    }
25
26
    /**
27
     * Bind untargeted binding
28
     */
29
    public function __invoke(Container $container, Bind $bind): void
30
    {
31
        $bound = (new DependencyFactory())->newAnnotatedDependency($this->class);
32
        $bound->setScope($this->scope);
33
34
        $bind->setBound($bound);
35
        $container->add($bind);
36
    }
37
38
    public function setScope(string $scope): void
39
    {
40
        $this->scope = $scope;
41
    }
42
}
43