Completed
Push — master ( d7ac59...64fa5b )
by Matthieu
02:28
created

FactoryDefinition::getParameters()   A

Complexity

Conditions 1
Paths 1

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 4
Code Lines 2

Importance

Changes 1
Bugs 1 Features 1
Metric Value
cc 1
eloc 2
c 1
b 1
f 1
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
     * Factory parameters.
33
     * @var array
34
     */
35
    private $parameters = [];
36
37
    /**
38
     * @param string      $name       Entry name
39
     * @param callable    $factory    Callable that returns the value associated to the entry name.
40
     * @param string|null $scope
41
     * @param array       $parameters Parameters to be passed to the callable
42
     */
43
    public function __construct($name, $factory, $scope = null, $parameters = [])
44
    {
45
        $this->name = $name;
46
        $this->factory = $factory;
47
        $this->scope = $scope;
48
        $this->parameters = $parameters;
49
    }
50
51
    /**
52
     * @return string Entry name.
53
     */
54
    public function getName()
55
    {
56
        return $this->name;
57
    }
58
59
    /**
60
     * Default scope is singleton: the callable is called once and the result is shared.
61
     *
62
     * {@inheritdoc}
63
     */
64
    public function getScope()
65
    {
66
        return $this->scope ?: Scope::SINGLETON;
67
    }
68
69
    /**
70
     * @return callable Callable that returns the value associated to the entry name.
71
     */
72
    public function getCallable()
73
    {
74
        return $this->factory;
75
    }
76
77
    /**
78
     * @return array Array containing the parameters to be passed to the callable, indexed by name.
79
     */
80
    public function getParameters()
81
    {
82
        return $this->parameters;
83
    }
84
85
    public function __toString()
86
    {
87
        return 'Factory';
88
    }
89
}
90