Skip to content

Commit 7c5ceea

Browse files
authored
v1.6.4 Allow forced override services (#12)
1 parent 0c7c0ae commit 7c5ceea

File tree

3 files changed

+4
-9
lines changed

3 files changed

+4
-9
lines changed

src/Container.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,16 @@ public function has(string $id): bool
6666
return !empty($this->servicesRaw[$id]) || !empty($this->services[$id]);
6767
}
6868

69-
/**
70-
* {@inheritDoc}
71-
*/
72-
public function register(string $id, callable $service): void
69+
public function register(string $id, callable $service, bool $force = false): void
7370
{
74-
if ($this->has($id)) {
71+
if ($this->has($id) && !$force) {
7572
throw new ServiceRegistrationException(sprintf('Service "%s" already registered', $id));
7673
}
7774

7875
$this->servicesRaw[$id] = $service;
7976
}
8077

8178
/**
82-
* {@inheritDoc}
83-
*
8479
* @psalm-suppress InvalidPropertyAssignmentValue
8580
*/
8681
public function decorate(string $id, callable $service, int $priority = 0): void

src/ContainerRegistryInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ interface ContainerRegistryInterface
2121
* @param class-string<T> $id service alias
2222
* @param callable $service service initialization callback
2323
*/
24-
public function register(string $id, callable $service): void;
24+
public function register(string $id, callable $service, bool $force = false): void;
2525
}

src/Exception/ServiceNotRegisteredException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ServiceNotRegisteredException extends \RuntimeException implements NotFoun
1717
{
1818
private string $serviceId;
1919

20-
public function __construct(string $serviceId, int $code = 0, ?\Throwable $previous = null)
20+
public function __construct(string $serviceId, int $code = 0, \Throwable $previous = null)
2121
{
2222
$this->serviceId = $serviceId;
2323

0 commit comments

Comments
 (0)