Skip to content

Commit

Permalink
option 'dynamic' and option 'class' used instead of 'create' are depr…
Browse files Browse the repository at this point in the history
…ecated
  • Loading branch information
dg committed Dec 14, 2022
1 parent 63c867c commit 7e5ec4a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
22 changes: 13 additions & 9 deletions src/DI/Extensions/DefinitionSchema.php
Expand Up @@ -105,15 +105,19 @@ public function normalize($def, Context $context)
unset($def['factory']);
}

if (
isset($def['class'])
&& !isset($def['type'])
&& !isset($def['create'])
&& !isset($def['dynamic'])
&& !isset($def['imported'])
) {
$def['create'] = $def['class'];
unset($def['class']);
if (isset($def['dynamic'])) {
trigger_error(sprintf("Service '%s': option 'dynamic' should be changed to 'imported'.", end($context->path)), E_USER_DEPRECATED);
}

if (isset($def['class'])) {
if (isset($def['dynamic']) || isset($def['imported'])) {
trigger_error(sprintf("Service '%s': option 'class' should be changed to 'type'.", end($context->path)), E_USER_DEPRECATED);

} elseif (!isset($def['type']) && !isset($def['create'])) {
trigger_error(sprintf("Service '%s': option 'class' should be changed to 'create'.", end($context->path)), E_USER_DEPRECATED);
$def['create'] = $def['class'];
unset($def['class']);
}
}

foreach (['class' => 'type', 'dynamic' => 'imported'] as $alias => $original) {
Expand Down
4 changes: 2 additions & 2 deletions tests/DI/Compiler.services.imported.phpt
Expand Up @@ -18,7 +18,7 @@ class Service
}


$container = createContainer(new DI\Compiler, '
$container = @createContainer(new DI\Compiler, '
services:
one:
type: Service
Expand All @@ -42,7 +42,7 @@ Assert::exception(function () use ($container) {
}, Nette\DI\ServiceCreationException::class, "Unable to create imported service 'one', it must be added using addService()");


$container = createContainer(new DI\Compiler, '
$container = @createContainer(new DI\Compiler, '
services:
one:
class: Service
Expand Down
4 changes: 2 additions & 2 deletions tests/DI/DefinitionSchema.normalize.phpt
Expand Up @@ -45,8 +45,8 @@ Assert::with(DefinitionSchema::class, function () {
Assert::same(['implement' => Iface::class, 'tagged' => 123], $schema->normalize($statement, $context));

// aliases
Assert::same(['create' => 'val'], $schema->normalize(['class' => 'val'], $context));
Assert::same(['imported' => 'val'], $schema->normalize(['dynamic' => 'val'], $context));
Assert::same(['create' => 'val'], @$schema->normalize(['class' => 'val'], $context)); // triggers notice
Assert::same(['imported' => 'val'], @$schema->normalize(['dynamic' => 'val'], $context)); // triggers notice

Assert::exception(function () use ($schema, $context) {
$schema->normalize(['class' => 'val', 'type' => 'val'], $context);
Expand Down
6 changes: 3 additions & 3 deletions tests/DI/files/compiler.extensionOverride.neon
Expand Up @@ -21,7 +21,7 @@ services:
one9:
type: Ipsum
one10:
class: Ipsum
create: Ipsum

two1:
factory: Ipsum
Expand Down Expand Up @@ -49,7 +49,7 @@ services:
two11:
type: Ipsum
two12:
class: Ipsum
create: Ipsum

three1:
factory: Ipsum
Expand All @@ -70,4 +70,4 @@ services:
three8:
type: Ipsum
three9:
class: Ipsum
create: Ipsum

0 comments on commit 7e5ec4a

Please sign in to comment.