@@ -8,5 +8,5 @@ |
||
| 8 | 8 | |
| 9 | 9 | abstract class Container implements ContainerInterface |
| 10 | 10 | { |
| 11 | - use ContainerTrait; |
|
| 11 | + use ContainerTrait; |
|
| 12 | 12 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |