Skip to content

Commit 35d925b

Browse files
committed
ContainerBuilder: removed needless checking of service's type
1 parent b7fd926 commit 35d925b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/DI/ContainerBuilder.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,15 +499,18 @@ private function generateService($name)
499499
);
500500
}
501501

502-
$serviceRef = $this->getServiceName($def->factory->entity);
502+
$entity = $def->factory->entity;
503+
$serviceRef = $this->getServiceName($entity);
503504
$factory = $serviceRef && !$def->factory->arguments && !$def->setup && $def->implementType !== 'create'
504505
? new Statement(array('@' . ContainerBuilder::THIS_CONTAINER, 'getService'), array($serviceRef))
505506
: $def->factory;
506507

507508
$code = '$service = ' . $this->formatStatement($factory) . ";\n";
508509
$this->currentService = $name;
509510

510-
if ($def->class && $def->class !== $def->factory->entity && !$serviceRef) {
511+
if ($def->class && !$serviceRef && $def->class !== $entity
512+
&& !(is_string($entity) && preg_match('#^[\w\\\\]+\z#', $entity) && is_subclass_of($entity, $def->class))
513+
) {
511514
$code .= PhpHelpers::formatArgs("if (!\$service instanceof $def->class) {\n"
512515
. "\tthrow new Nette\\UnexpectedValueException(?);\n}\n",
513516
array("Unable to create service '$name', value returned by factory is not $def->class type.")

0 commit comments

Comments
 (0)