Skip to content

Commit

Permalink
Compiler: removed support for \ in service name (BC break)
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jun 4, 2015
1 parent 9023712 commit 72bc3f0
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/DI/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,12 @@ public static function parseServices(ContainerBuilder $builder, array $config, $
}
array_multisort($depths, $services);

foreach ($services as $origName => $def) {
if ((string) (int) $origName === (string) $origName) {
foreach ($services as $name => $def) {
if ((string) (int) $name === (string) $name) {
$postfix = $def instanceof Statement && is_string($def->getEntity()) ? '.' . $def->getEntity() : (is_scalar($def) ? ".$def" : '');
$name = (count($builder->getDefinitions()) + 1) . preg_replace('#\W+#', '_', $postfix);
} else {
$name = ($namespace ? $namespace . '.' : '') . strtr($origName, '\\', '_');
} elseif ($namespace) {
$name = $namespace . '.' . $name;
}

$params = $builder->parameters;
Expand Down

8 comments on commit 72bc3f0

@norbe
Copy link

@norbe norbe commented on 72bc3f0 Jul 28, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's reason for this? We are using it quit a lot as IDE is able to suggest me the name of service in neon file and I can easily change her configuration.

@norbe
Copy link

@norbe norbe commented on 72bc3f0 Aug 10, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @dg

@dg
Copy link
Member Author

@dg dg commented on 72bc3f0 Aug 10, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because syntax Class\Name: self is deprecated for long time 48388d9 and replaced with - Class\Name.

@norbe
Copy link

@norbe norbe commented on 72bc3f0 Aug 10, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, but it's not the same.

Let's say that I've got and interface Namespace\IFoo. So I create a service with name Namespace\IFoo and specify the default impementation by class option. When I need to overwrite it or add some setup in local config, I do not need to think about the name of service and simple use her class name. It's simple and efective.

Example:
module.neon:

services:
   Namespace\IFoo:
      class: Namespace\Foo

config.local.neon:

services:
   Namespace\IFoo:
      setup: 
         - setBar('foo')

@dg
Copy link
Member Author

@dg dg commented on 72bc3f0 Aug 10, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand, but this can lead to confusion, referencing via name @Namespace\IFoo will not work as expected:

services:
   Namespace\IFoo:
      class: stdClass

   - Application(@Namespace\IFoo)  #service is missing

@norbe
Copy link

@norbe norbe commented on 72bc3f0 Aug 10, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it's becouse of this? Maybe we could check if class is of type $serviceName?

@dg
Copy link
Member Author

@dg dg commented on 72bc3f0 Aug 10, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could check if class is of type $serviceName?

It is hard and it is not enough. Simply Namespace\IFoo: is name (no inheritance, case sensitive), it is not class/interface name, but it looks like class name (inheritance, case insensitive).

@norbe
Copy link

@norbe norbe commented on 72bc3f0 Aug 10, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I understand...

Please sign in to comment.