Skip to content

Commit

Permalink
Container: removed $types
Browse files Browse the repository at this point in the history
It was used only for imported services, which is now solved by typehint
  • Loading branch information
dg committed Apr 28, 2024
1 parent f1274cf commit b4ef1fa
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/Bridges/DITracy/ContainerPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function getPanel(): string
foreach ($rc->getMethods() as $method) {
if (preg_match('#^createService.#', $method->getName())) {
$name = lcfirst(str_replace('__', '.', substr($method->getName(), 13)));
$services[$name] = $this->container->getServiceType($name);
$services[$name] = (string) $method->getReturnType();
}
}
ksort($services, SORT_NATURAL);
Expand Down
6 changes: 0 additions & 6 deletions src/DI/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ class Container
*/
public $parameters = [];

/** @var string[] service name => type */
protected array $types = [];

/** @var string[] alias => service name */
protected array $aliases = [];

Expand Down Expand Up @@ -171,9 +168,6 @@ public function getServiceType(string $name): string
if (isset($this->aliases[$name])) {
return $this->getServiceType($this->aliases[$name]);

} elseif (isset($this->types[$name])) {
return $this->types[$name];

} elseif (isset($this->methods[$method])) {
return (string) (new \ReflectionMethod($this, $method))->getReturnType();

Expand Down
4 changes: 0 additions & 4 deletions src/DI/ContainerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,6 @@ public function exportMeta(): array
$defs = $this->definitions;
ksort($defs);
foreach ($defs as $name => $def) {
if ($def instanceof Definitions\ImportedDefinition) {
$meta['types'][$name] = $def->getType();
}

foreach ($def->getTags() as $tag => $value) {
$meta['tags'][$tag][$name] = $value;
}
Expand Down
9 changes: 4 additions & 5 deletions src/DI/Definitions/ImportedDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ public function complete(Nette\DI\Resolver $resolver): void

public function generateMethod(Nette\PhpGenerator\Method $method, PhpGenerator $generator): void
{
$method->setReturnType('void')
->setBody(
'throw new Nette\\DI\\ServiceCreationException(?);',
["Unable to create imported service '{$this->getName()}', it must be added using addService()"],
);
$method->setBody(
'throw new Nette\\DI\\ServiceCreationException(?);',
["Unable to create imported service '{$this->getName()}', it must be added using addService()"],
);
}
}
5 changes: 0 additions & 5 deletions tests/DI/ContainerBuilder.metadata.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ Assert::same(
getPropertyValue($container, 'wiring'),
);

Assert::same(
['container' => Nette\DI\Container::class],
getPropertyValue($container, 'types'),
);

Assert::same(
[
'a' => ['lorem' => true],
Expand Down
2 changes: 1 addition & 1 deletion tests/DI/Definitions.ImportedDefinition.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ test('', function () {

Assert::match(
<<<'XX'
public function createServiceAbc(): void
public function createServiceAbc(): stdClass
{
throw new Nette\DI\ServiceCreationException('Unable to create imported service \'abc\', it must be added using addService()');
}
Expand Down
1 change: 0 additions & 1 deletion tests/DI/expected/compiler.code.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

class Container extends Nette\DI\Container
{
protected array $types = ['container' => 'Nette\DI\Container'];
protected array $aliases = [];
protected array $wiring = ['Nette\DI\Container' => [['container']], 'stdClass' => [['01', 'name']]];

Expand Down

0 comments on commit b4ef1fa

Please sign in to comment.