Skip to content

Commit a151e4e

Browse files
committed
Container: removed $types
It was used only for imported services, which is now solved by typehint
1 parent 067cdf5 commit a151e4e

8 files changed

+6
-24
lines changed

src/Bridges/DITracy/ContainerPanel.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function getPanel(): string
5555
foreach ($rc->getMethods() as $method) {
5656
if (preg_match('#^createService.#', $method->getName())) {
5757
$name = lcfirst(str_replace('__', '.', substr($method->getName(), 13)));
58-
$services[$name] = $this->container->getServiceType($name);
58+
$services[$name] = (string) $method->getReturnType();
5959
}
6060
}
6161
ksort($services, SORT_NATURAL);

src/DI/Container.php

-6
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ class Container
2323
*/
2424
public $parameters = [];
2525

26-
/** @var string[] service name => type */
27-
protected array $types = [];
28-
2926
/** @var string[] alias => service name */
3027
protected array $aliases = [];
3128

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

174-
} elseif (isset($this->types[$name])) {
175-
return $this->types[$name];
176-
177171
} elseif (isset($this->methods[$method])) {
178172
return (string) (new \ReflectionMethod($this, $method))->getReturnType();
179173

src/DI/ContainerBuilder.php

-4
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,6 @@ public function exportMeta(): array
353353
$defs = $this->definitions;
354354
ksort($defs);
355355
foreach ($defs as $name => $def) {
356-
if ($def instanceof Definitions\ImportedDefinition) {
357-
$meta['types'][$name] = $def->getType();
358-
}
359-
360356
foreach ($def->getTags() as $tag => $value) {
361357
$meta['tags'][$tag][$name] = $value;
362358
}

src/DI/Definitions/ImportedDefinition.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ public function complete(Nette\DI\Resolver $resolver): void
3636

3737
public function generateMethod(Nette\PhpGenerator\Method $method, PhpGenerator $generator): void
3838
{
39-
$method->setReturnType('void')
40-
->setBody(
41-
'throw new Nette\\DI\\ServiceCreationException(?);',
42-
["Unable to create imported service '{$this->getName()}', it must be added using addService()"],
43-
);
39+
$method->setBody(
40+
'throw new Nette\\DI\\ServiceCreationException(?);',
41+
["Unable to create imported service '{$this->getName()}', it must be added using addService()"],
42+
);
4443
}
4544
}

src/DI/PhpGenerator.php

-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public function generate(string $className): Php\ClassType
5555
}
5656

5757
$class->getMethod(Container::getMethodName(ContainerBuilder::ThisContainer))
58-
->setReturnType($className)
5958
->setBody('return $this;');
6059

6160
$class->inheritMethod('initialize');

tests/DI/ContainerBuilder.metadata.phpt

-5
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ Assert::same(
4141
getPropertyValue($container, 'wiring'),
4242
);
4343

44-
Assert::same(
45-
['container' => Nette\DI\Container::class],
46-
getPropertyValue($container, 'types'),
47-
);
48-
4944
Assert::same(
5045
[
5146
'a' => ['lorem' => true],

tests/DI/Definitions.ImportedDefinition.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ test('', function () {
4242

4343
Assert::match(
4444
<<<'XX'
45-
public function createServiceAbc(): void
45+
public function createServiceAbc(): stdClass
4646
{
4747
throw new Nette\DI\ServiceCreationException('Unable to create imported service \'abc\', it must be added using addService()');
4848
}

tests/DI/expected/compiler.code.php

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
class Container extends Nette\DI\Container
88
{
9-
protected array $types = ['container' => 'Nette\DI\Container'];
109
protected array $aliases = [];
1110
protected array $wiring = ['Nette\DI\Container' => [['container']], 'stdClass' => [['01', 'name']]];
1211

0 commit comments

Comments
 (0)