Completed
Push — master ( 95a6e8...b8af6d )
by Filipe
07:12
created

AbstractDefinition::setScope()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
/**
4
 * This file is part of slick/di package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\Di\Definition;
11
12
use Interop\Container\ContainerInterface;
13
use Slick\Common\Base;
14
use Slick\Di\DefinitionInterface;
15
16
/**
17
 * A base class for all definitions
18
 *
19
 * @package Slick\Tests\Di\Definition
20
 *
21
 * @property string $name  Definition name or key
22
 * @property Scope  $scope Definition scope: Prototype or Singleton
23
 *
24
 * @property $this|AbstractDefinition setName(string $name) Sets definition
25
 *                                                          name.
26
 */
27
abstract class AbstractDefinition extends Base implements DefinitionInterface
28
{
29
30
    /**
31
     * @readwrite
32
     * @var string
33
     */
34
    protected $name;
35
36
    /**
37
     * @readwrite
38
     * @var Scope
39
     */
40
    protected $scope;
41
42
    /**
43
     * @readwrite
44
     * @var ContainerInterface
45
     */
46
    protected $container;
47
48
    /**
49
     * Initializes the
50
     * @param array $options
51
     */
52 84
    public function __construct($options = [])
53
    {
54 84
        $options = array_replace(
55
            [
56 84
                'scope' => new Scope(Scope::SINGLETON)
57 84
            ],
58
            $options
59 84
        );
60 84
        parent::__construct($options);
61 84
    }
62
63
    /**
64
     * Gets current definition name
65
     *
66
     * @return mixed
67
     */
68 72
    public function getName()
69
    {
70 72
        return $this->name;
71
    }
72
73
    /**
74
     * Gets the scope for current definition
75
     *
76
     * @return Scope
77
     */
78 50
    public function getScope()
79
    {
80 50
        return new Scope((string) $this->scope);
81
    }
82
83
    /**
84
     * Sets definition scope
85
     *
86
     * @param Scope $scope The scope type
87
     * @return $this|self
88
     */
89 84
    public function setScope(Scope $scope)
90
    {
91 84
        $this->scope = $scope;
92 84
        return $this;
93
    }
94
95
    /**
96
     * Set container for this definition
97
     *
98
     * @param ContainerInterface $container
99
     *
100
     * @return $this|self
101
     */
102 74
    public function setContainer(ContainerInterface $container)
103
    {
104 74
        $this->container = $container;
105 74
        return $this;
106
    }
107
108
    /**
109
     * Gets container
110
     *
111
     * @return ContainerInterface
112
     */
113 38
    public function getContainer()
114
    {
115 38
        return $this->container;
116
    }
117
}
118