Skip to content

Commit

Permalink
Revert "used generics (#261)" [Closes #274]
Browse files Browse the repository at this point in the history
This reverts commit 927cf12.
  • Loading branch information
dg committed Jan 16, 2023
1 parent 4d94f3a commit bb08328
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/DI/Container.php
Expand Up @@ -232,9 +232,7 @@ public function createService(string $name, array $args = [])

/**
* Resolves service by type.
* @template T
* @param class-string<T> $type
* @return ?T
* @return object|null service
* @throws MissingServiceException
*/
public function getByType(string $type, bool $throw = true)
Expand Down
34 changes: 34 additions & 0 deletions tests/DI/ContainerBuilder.resolve.Container.phpt
@@ -0,0 +1,34 @@
<?php

/**
* Test: Nette\DI\Container::getByType() can be resolved
*/

declare(strict_types=1);

use Nette\DI;
use Tester\Assert;

require __DIR__ . '/../bootstrap.php';


class Lorem
{
public function next(): stdClass
{
return new stdClass;
}
}


$container = createContainer(new DI\Compiler, '
services:
lorem: Lorem
next:
factory: @container::getByType(Lorem)::next()
type: stdClass
');


Assert::type(stdClass::class, $container->getService('next'));

0 comments on commit bb08328

Please sign in to comment.