@@ -8,5 +8,5 @@ |
||
8 | 8 | |
9 | 9 | abstract class Container implements ContainerInterface |
10 | 10 | { |
11 | - use ContainerTrait; |
|
11 | + use ContainerTrait; |
|
12 | 12 | } |
@@ -6,7 +6,6 @@ |
||
6 | 6 | |
7 | 7 | namespace Yep\Container; |
8 | 8 | |
9 | -abstract class Container implements ContainerInterface |
|
10 | -{ |
|
9 | +abstract class Container implements ContainerInterface { |
|
11 | 10 | use ContainerTrait; |
12 | 11 | } |
@@ -8,8 +8,8 @@ |
||
8 | 8 | |
9 | 9 | class ServiceNotFoundException extends ContainerException |
10 | 10 | { |
11 | - public static function create($name) |
|
12 | - { |
|
13 | - return new self(sprintf('Service "%s" not found!', $name)); |
|
14 | - } |
|
11 | + public static function create($name) |
|
12 | + { |
|
13 | + return new self(sprintf('Service "%s" not found!', $name)); |
|
14 | + } |
|
15 | 15 | } |
@@ -6,10 +6,8 @@ |
||
6 | 6 | |
7 | 7 | namespace Yep\Container\Exception; |
8 | 8 | |
9 | -class ServiceNotFoundException extends ContainerException |
|
10 | -{ |
|
11 | - public static function create($name) |
|
12 | - { |
|
9 | +class ServiceNotFoundException extends ContainerException { |
|
10 | + public static function create($name) { |
|
13 | 11 | return new self(sprintf('Service "%s" not found!', $name)); |
14 | 12 | } |
15 | 13 | } |
@@ -8,13 +8,13 @@ |
||
8 | 8 | |
9 | 9 | class ServiceMustBeAnObjectException extends ContainerException |
10 | 10 | { |
11 | - public static function create($service) |
|
12 | - { |
|
13 | - return new self( |
|
14 | - sprintf( |
|
15 | - 'Service factory must return an object, got "%s"!', |
|
16 | - gettype($service) |
|
17 | - ) |
|
18 | - ); |
|
19 | - } |
|
11 | + public static function create($service) |
|
12 | + { |
|
13 | + return new self( |
|
14 | + sprintf( |
|
15 | + 'Service factory must return an object, got "%s"!', |
|
16 | + gettype($service) |
|
17 | + ) |
|
18 | + ); |
|
19 | + } |
|
20 | 20 | } |
@@ -6,10 +6,8 @@ |
||
6 | 6 | |
7 | 7 | namespace Yep\Container\Exception; |
8 | 8 | |
9 | -class ServiceMustBeAnObjectException extends ContainerException |
|
10 | -{ |
|
11 | - public static function create($service) |
|
12 | - { |
|
9 | +class ServiceMustBeAnObjectException extends ContainerException { |
|
10 | + public static function create($service) { |
|
13 | 11 | return new self( |
14 | 12 | sprintf( |
15 | 13 | 'Service factory must return an object, got "%s"!', |
@@ -6,6 +6,5 @@ |
||
6 | 6 | |
7 | 7 | namespace Yep\Container\Exception; |
8 | 8 | |
9 | -class ContainerException extends \Exception |
|
10 | -{ |
|
9 | +class ContainerException extends \Exception { |
|
11 | 10 | } |
@@ -8,7 +8,7 @@ |
||
8 | 8 | |
9 | 9 | interface ContainerInterface |
10 | 10 | { |
11 | - public function getService($name); |
|
11 | + public function getService($name); |
|
12 | 12 | |
13 | - public function getParameter($key, $default = null); |
|
13 | + public function getParameter($key, $default = null); |
|
14 | 14 | } |
@@ -6,8 +6,7 @@ |
||
6 | 6 | |
7 | 7 | namespace Yep\Container; |
8 | 8 | |
9 | -interface ContainerInterface |
|
10 | -{ |
|
9 | +interface ContainerInterface { |
|
11 | 10 | public function getService($name); |
12 | 11 | |
13 | 12 | public function getParameter($key, $default = null); |
@@ -11,70 +11,70 @@ |
||
11 | 11 | |
12 | 12 | trait ContainerTrait |
13 | 13 | { |
14 | - protected $parameters = []; |
|
15 | - protected $services = []; |
|
14 | + protected $parameters = []; |
|
15 | + protected $services = []; |
|
16 | 16 | |
17 | - public function __construct(array $parameters = []) |
|
18 | - { |
|
19 | - $this->parameters = $parameters; |
|
20 | - } |
|
17 | + public function __construct(array $parameters = []) |
|
18 | + { |
|
19 | + $this->parameters = $parameters; |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
23 | - * @param string $key |
|
24 | - * @param mixed $value |
|
25 | - */ |
|
26 | - public function setParameter($key, $value) |
|
27 | - { |
|
28 | - $this->parameters[$key] = $value; |
|
29 | - } |
|
22 | + /** |
|
23 | + * @param string $key |
|
24 | + * @param mixed $value |
|
25 | + */ |
|
26 | + public function setParameter($key, $value) |
|
27 | + { |
|
28 | + $this->parameters[$key] = $value; |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * @param string $key |
|
33 | - * @param mixed $default |
|
34 | - * @return mixed |
|
35 | - */ |
|
36 | - public function getParameter($key, $default = null) |
|
37 | - { |
|
38 | - if (isset($this->parameters[$key])) { |
|
39 | - return $this->parameters[$key]; |
|
40 | - } |
|
31 | + /** |
|
32 | + * @param string $key |
|
33 | + * @param mixed $default |
|
34 | + * @return mixed |
|
35 | + */ |
|
36 | + public function getParameter($key, $default = null) |
|
37 | + { |
|
38 | + if (isset($this->parameters[$key])) { |
|
39 | + return $this->parameters[$key]; |
|
40 | + } |
|
41 | 41 | |
42 | - return $default; |
|
43 | - } |
|
42 | + return $default; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * @param string $name |
|
47 | - * @param object $service |
|
48 | - * @return mixed |
|
49 | - * @throws ServiceMustBeAnObjectException |
|
50 | - */ |
|
51 | - public function setService($name, $service) |
|
52 | - { |
|
53 | - if (!is_object($service)) { |
|
54 | - throw ServiceMustBeAnObjectException::create($service); |
|
55 | - } |
|
45 | + /** |
|
46 | + * @param string $name |
|
47 | + * @param object $service |
|
48 | + * @return mixed |
|
49 | + * @throws ServiceMustBeAnObjectException |
|
50 | + */ |
|
51 | + public function setService($name, $service) |
|
52 | + { |
|
53 | + if (!is_object($service)) { |
|
54 | + throw ServiceMustBeAnObjectException::create($service); |
|
55 | + } |
|
56 | 56 | |
57 | - return $this->services[$name] = $service; |
|
58 | - } |
|
57 | + return $this->services[$name] = $service; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @param string $name |
|
62 | - * @return mixed |
|
63 | - * @throws ServiceMustBeAnObjectException |
|
64 | - * @throws ServiceNotFoundException |
|
65 | - */ |
|
66 | - public function getService($name) |
|
67 | - { |
|
68 | - if (isset($this->services[$name])) { |
|
69 | - return $this->services[$name]; |
|
70 | - } |
|
60 | + /** |
|
61 | + * @param string $name |
|
62 | + * @return mixed |
|
63 | + * @throws ServiceMustBeAnObjectException |
|
64 | + * @throws ServiceNotFoundException |
|
65 | + */ |
|
66 | + public function getService($name) |
|
67 | + { |
|
68 | + if (isset($this->services[$name])) { |
|
69 | + return $this->services[$name]; |
|
70 | + } |
|
71 | 71 | |
72 | - if (!method_exists($this, $name.'Factory')) { |
|
73 | - throw ServiceNotFoundException::create($name); |
|
74 | - } |
|
72 | + if (!method_exists($this, $name.'Factory')) { |
|
73 | + throw ServiceNotFoundException::create($name); |
|
74 | + } |
|
75 | 75 | |
76 | - $service = $this->{$name.'Factory'}(); |
|
76 | + $service = $this->{$name.'Factory'}(); |
|
77 | 77 | |
78 | - return $this->setService($name, $service); |
|
79 | - } |
|
78 | + return $this->setService($name, $service); |
|
79 | + } |
|
80 | 80 | } |
@@ -69,11 +69,11 @@ |
||
69 | 69 | return $this->services[$name]; |
70 | 70 | } |
71 | 71 | |
72 | - if (!method_exists($this, $name.'Factory')) { |
|
72 | + if (!method_exists($this, $name . 'Factory')) { |
|
73 | 73 | throw ServiceNotFoundException::create($name); |
74 | 74 | } |
75 | 75 | |
76 | - $service = $this->{$name.'Factory'}(); |
|
76 | + $service = $this->{$name . 'Factory'}(); |
|
77 | 77 | |
78 | 78 | return $this->setService($name, $service); |
79 | 79 | } |
@@ -9,13 +9,11 @@ discard block |
||
9 | 9 | use Yep\Container\Exception\ServiceMustBeAnObjectException; |
10 | 10 | use Yep\Container\Exception\ServiceNotFoundException; |
11 | 11 | |
12 | -trait ContainerTrait |
|
13 | -{ |
|
12 | +trait ContainerTrait { |
|
14 | 13 | protected $parameters = []; |
15 | 14 | protected $services = []; |
16 | 15 | |
17 | - public function __construct(array $parameters = []) |
|
18 | - { |
|
16 | + public function __construct(array $parameters = []) { |
|
19 | 17 | $this->parameters = $parameters; |
20 | 18 | } |
21 | 19 | |
@@ -23,8 +21,7 @@ discard block |
||
23 | 21 | * @param string $key |
24 | 22 | * @param mixed $value |
25 | 23 | */ |
26 | - public function setParameter($key, $value) |
|
27 | - { |
|
24 | + public function setParameter($key, $value) { |
|
28 | 25 | $this->parameters[$key] = $value; |
29 | 26 | } |
30 | 27 | |
@@ -33,8 +30,7 @@ discard block |
||
33 | 30 | * @param mixed $default |
34 | 31 | * @return mixed |
35 | 32 | */ |
36 | - public function getParameter($key, $default = null) |
|
37 | - { |
|
33 | + public function getParameter($key, $default = null) { |
|
38 | 34 | if (isset($this->parameters[$key])) { |
39 | 35 | return $this->parameters[$key]; |
40 | 36 | } |
@@ -48,8 +44,7 @@ discard block |
||
48 | 44 | * @return mixed |
49 | 45 | * @throws ServiceMustBeAnObjectException |
50 | 46 | */ |
51 | - public function setService($name, $service) |
|
52 | - { |
|
47 | + public function setService($name, $service) { |
|
53 | 48 | if (!is_object($service)) { |
54 | 49 | throw ServiceMustBeAnObjectException::create($service); |
55 | 50 | } |
@@ -63,8 +58,7 @@ discard block |
||
63 | 58 | * @throws ServiceMustBeAnObjectException |
64 | 59 | * @throws ServiceNotFoundException |
65 | 60 | */ |
66 | - public function getService($name) |
|
67 | - { |
|
61 | + public function getService($name) { |
|
68 | 62 | if (isset($this->services[$name])) { |
69 | 63 | return $this->services[$name]; |
70 | 64 | } |