Completed
Push — master ( 1feeef...279c4f )
by Matthieu
8s
created

FactoryDefinition::__toString()   A

Complexity

Conditions 1
Paths 1

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 4
Code Lines 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace DI\Definition;
4
5
use DI\Scope;
6
7
/**
8
 * Definition of a value or class with a factory.
9
 *
10
 * @author Matthieu Napoli <[email protected]>
11
 */
12
class FactoryDefinition implements Definition
13
{
14
    /**
15
     * Entry name.
16
     * @var string
17
     */
18
    private $name;
19
20
    /**
21
     * @var string
22
     */
23
    private $scope;
24
25
    /**
26
     * Callable that returns the value.
27
     * @var callable
28
     */
29
    private $factory;
30
31
    /**
32
     * @param string      $name    Entry name
33
     * @param callable    $factory Callable that returns the value associated to the entry name.
34
     * @param string|null $scope
35
     */
36
    public function __construct($name, $factory, $scope = null)
37
    {
38
        $this->name = $name;
39
        $this->factory = $factory;
40
        $this->scope = $scope;
41
    }
42
43
    /**
44
     * @return string Entry name.
45
     */
46
    public function getName()
47
    {
48
        return $this->name;
49
    }
50
51
    /**
52
     * Default scope is singleton: the callable is called once and the result is shared.
53
     *
54
     * {@inheritdoc}
55
     */
56
    public function getScope()
57
    {
58
        return $this->scope ?: Scope::SINGLETON;
59
    }
60
61
    /**
62
     * @return callable Callable that returns the value associated to the entry name.
63
     */
64
    public function getCallable()
65
    {
66
        return $this->factory;
67
    }
68
69
    public function __toString()
70
    {
71
        return 'Factory';
72
    }
73
}
74