Container::getParameters()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
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
namespace Genesis\Config;
5
6
7
use Genesis\MemberAccessException;
8
9
10
/**
11
 * @author Adam Bisek <[email protected]>
12
 */
13
class Container implements \IteratorAggregate
14
{
15
16
	/** @var string */
17
	private $class;
18
19
	/** @var array */
20
	private $parameters = [];
21
22
	private $services = [];
23
24
25 12
	public function getClass()
26
	{
27 12
		return $this->class;
28
	}
29
30
31 14
	public function setClass($class)
32
	{
33 14
		$this->class = $class;
34 14
	}
35
36
37 4
	public function getParameter($name)
38
	{
39 4
		if (!array_key_exists($name, $this->parameters)) {
40 1
			throw new MemberAccessException("Config key '$name' does not exists.");
41
		}
42 3
		return $this->parameters[$name];
43
	}
44
45
46 12
	public function getParameters()
47
	{
48 12
		return $this->parameters;
49
	}
50
51
52 3
	public function setParameter($name, $value)
53
	{
54 3
		$this->parameters[$name] = $value;
55 3
	}
56
57
58 14
	public function setParameters($parameters)
59
	{
60 14
		$this->parameters = $parameters;
61 14
	}
62
63
64 12
	public function getServices()
65
	{
66 12
		return $this->services;
67
	}
68
69
70 11
	public function getService($name)
71
	{
72 11
		if (!isset($this->services[$name])) {
73 1
			throw new MemberAccessException("Service '$name' does not exists.");
74
		}
75 10
		return $this->services[$name];
76
	}
77
78
79 11
	public function hasService($name)
80
	{
81 11
		return isset($this->services[$name]);
82
	}
83
84
85 13
	public function addService($name, $service)
86
	{
87 13
		$this->services[$name] = $service;
88 13
	}
89
90
91 1
	public function getIterator()
92
	{
93 1
		return new \ArrayIterator($this->parameters);
94
	}
95
96
97 1
	public function &__get($name)
98
	{
99 1
		throw new MemberAccessException("Direct getting is not supported. Use setParameter('$name') instead.");
100
	}
101
102
103 1
	public function __set($name, $value)
104
	{
105 1
		throw new MemberAccessException("Direct setting is not supported. Use setParameter('$name', ...) instead.");
106
	}
107
108
}