Skip to content

Commit 1c95b65

Browse files
committed
fix(container): ensure last registration wins and simplify spec path resolution
1 parent 79450df commit 1c95b65

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

config/routes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
return static function (Application $application, MiddlewareFactory $middlewareFactory): void {
1414
$specPath = getenv('OPENAPI_SPEC') ?: null;
15-
$packageRoot = dirname(__DIR__) ?: '/app';
15+
$packageRoot = dirname(__DIR__);
1616

1717
if (null === $specPath) {
1818
$specPath = $packageRoot . '/data/openapi.yaml';

src/Container/SimpleContainer.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,22 +159,25 @@ public function configure(array $config): void
159159

160160
public function setService(string $name, mixed $service): void
161161
{
162+
unset($this->aliases[$name], $this->factories[$name]);
162163
$this->services[$name] = $service;
163164
}
164165

165166
public function setFactory(string $name, callable|string $factory): void
166167
{
168+
unset($this->aliases[$name], $this->services[$name]);
167169
$this->factories[$name] = $factory;
168170
}
169171

170172
public function setAlias(string $alias, string $target): void
171173
{
174+
unset($this->services[$alias], $this->factories[$alias]);
172175
$this->aliases[$alias] = $target;
173176
}
174177

175178
public function setInvokableClass(string $name, string $class): void
176179
{
177-
$this->factories[$name] = static fn (): object => new $class();
180+
$this->setFactory($name, static fn (): object => new $class());
178181
}
179182

180183
private function resolveAlias(string $id, bool $throwOnCircular = true): ?string

0 commit comments

Comments
 (0)