@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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); |
@@ -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 | } |