DependencyDefinition::getScope()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * Copyright (c) 2011-2015, Celestino Diaz <[email protected]>
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7
 * of this software and associated documentation files (the "Software"), to deal
8
 * in the Software without restriction, including without limitation the rights
9
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
 * copies of the Software, and to permit persons to whom the Software is
11
 * furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included in
14
 * all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
 * THE SOFTWARE.
23
 */
24
25
namespace Brickoo\Component\IoC\Definition;
26
27
use Brickoo\Component\IoC\Definition\Container\ArgumentDefinitionContainer;
28
use Brickoo\Component\IoC\Definition\Container\InjectionDefinitionContainer;
29
use Brickoo\Component\Common\Assert;
30
31
/**
32
 * DependencyDefinition
33
 *
34
 * Implements a dependency definition.
35
 * @author Celestino Diaz <[email protected]>
36
 */
37
class DependencyDefinition {
38
39
    /** Scope definitions */
40
    const SCOPE_SINGLETON = 1;
41
    const SCOPE_PROTOTYPE = 2;
42
43
    /** @var \Brickoo\Component\IoC\Definition\Container\ArgumentDefinitionContainer */
44
    private $argumentsContainer;
45
46
    /** @var \Brickoo\Component\IoC\Definition\Container\InjectionDefinitionContainer */
47
    private $injectionsContainer;
48
49
    /** @var mixed */
50
    private $dependency;
51
52
    /** @var integer */
53
    private $scope;
54
55
    /**
56
     * Class constructor.
57
     * @param mixed $dependency
58
     * @param integer $scope
59
     * @param null|\Brickoo\Component\IoC\Definition\Container\ArgumentDefinitionContainer $argumentsContainer
60
     * @param null|\Brickoo\Component\IoC\Definition\Container\InjectionDefinitionContainer $injectionsContainer
61
     */
62 1
    public function __construct(
63
        $dependency,
64
        $scope = self::SCOPE_PROTOTYPE,
65
        ArgumentDefinitionContainer $argumentsContainer = null,
66
        InjectionDefinitionContainer $injectionsContainer = null) {
67 1
            Assert::isInteger($scope);
68 1
            $this->scope = $scope;
69 1
            $this->setDependency($dependency);
70 1
            $this->argumentsContainer = $argumentsContainer ?: new ArgumentDefinitionContainer();
71 1
            $this->injectionsContainer = $injectionsContainer ?: new InjectionDefinitionContainer();
72 1
    }
73
74
    /**
75
     * Return the dependency scope.
76
     * @return integer the dependency scope
77
     */
78 1
    public function getScope() {
79 1
        return $this->scope;
80
    }
81
82
    /**
83
     * Return the dependency arguments definitions container.
84
     * @return \Brickoo\Component\IoC\Definition\Container\ArgumentDefinitionContainer
85
     */
86 1
    public function getArgumentsContainer() {
87 1
        return $this->argumentsContainer;
88
    }
89
90
    /**
91
     * Return the dependency injection definitions container.
92
     * @return \Brickoo\Component\IoC\Definition\Container\InjectionDefinitionContainer
93
     */
94 1
    public function getInjectionsContainer() {
95 1
        return $this->injectionsContainer;
96
    }
97
98
    /**
99
     * Return the dependency provided.
100
     * @return mixed
101
     */
102 1
    public function getDependency() {
103 1
        return $this->dependency;
104
    }
105
106
    /**
107
     * Set the dependency of the definition.
108
     * @param mixed $dependency
109
     * @return \Brickoo\Component\IoC\Definition\DependencyDefinition
110
     */
111 1
    public function setDependency($dependency) {
112 1
        $this->dependency = $dependency;
113 1
        return $this;
114
    }
115
116
}
117