Skip to content

Commit

Permalink
allows service overwriting
Browse files Browse the repository at this point in the history
  • Loading branch information
tenmajkl committed Aug 14, 2022
1 parent ad9f278 commit 079f124
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 16 deletions.
5 changes: 0 additions & 5 deletions src/Lemon/Kernel/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public function get(string $id): mixed
/**
* Adds new service.
*
* @throws \Lemon\Kernel\Exceptions\ContainerException
* @throws \Lemon\Kernel\Exceptions\NotFoundException
*/
public function add(string $service, object $instance = null): static
Expand All @@ -62,10 +61,6 @@ public function add(string $service, object $instance = null): static
throw new NotFoundException('Class '.$service.' does not exist');
}

if (Arr::has($this->services, $service)) {
throw new ContainerException('Service '.$service.' is already registered');
}

$this->services[$service] = $instance;

return $this;
Expand Down
2 changes: 1 addition & 1 deletion src/Lemon/Routing/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Collection
/**
* Adds route to collection.
*/
public function add(string $path, string $method, callable $action): Route
public function add(string $path, string $method, callable|array $action): Route
{
$path = trim($path, '/');
if ($this->has($path)) {
Expand Down
16 changes: 8 additions & 8 deletions src/Lemon/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
/**
* The Lemon Router.
*
* @method \Lemon\Routing\Route get(string $path, $action) Creates route with method get
* @method \Lemon\Routing\Route post(string $path, $action) Creates route with method post
* @method \Lemon\Routing\Route put(string $path, $action) Creates route with method put
* @method \Lemon\Routing\Route head(string $path, $action) Creates route with method head
* @method \Lemon\Routing\Route delete(string $path, $action) Creates route with method delete
* @method \Lemon\Routing\Route path(string $path, $action) Creates route with method path
* @method \Lemon\Routing\Route options(string $path, $action) Creates route with method options
* @method \Lemon\Routing\Route get(string $path, callable|array $action) Creates route with method get
* @method \Lemon\Routing\Route post(string $path, callable|array $action) Creates route with method post
* @method \Lemon\Routing\Route put(string $path, callable|array $action) Creates route with method put
* @method \Lemon\Routing\Route head(string $path, callable|array $action) Creates route with method head
* @method \Lemon\Routing\Route delete(string $path, callable|array $action) Creates route with method delete
* @method \Lemon\Routing\Route path(string $path, callable|array $action) Creates route with method path
* @method \Lemon\Routing\Route options(string $path, callable|array $action) Creates route with method options
*/
class Router
{
Expand Down Expand Up @@ -58,7 +58,7 @@ public function __call($name, $arguments)
/**
* Creates new route with every request method.
*/
public function any(string $path, callable $action): Route
public function any(string $path, callable|array $action): Route
{
foreach (self::REQUEST_METHODS as $method) {
$this->routes->add($path, $method, $action);
Expand Down
2 changes: 0 additions & 2 deletions tests/Kernel/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public function testAddService()
$container->add(Bar::class);
$this->assertSame([Foo::class, Bar::class], $container->services());

$this->expectException(ContainerException::class);
$container->add(Foo::class);
$this->expectException(NotFoundException::class);
$container->add('Klobna');
}
Expand Down

0 comments on commit 079f124

Please sign in to comment.