Skip to content

Commit 5cc1648

Browse files
[DI] Generate shorter method names for class-based ids
1 parent 8e517f6 commit 5cc1648

File tree

4 files changed

+28
-20
lines changed

4 files changed

+28
-20
lines changed

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1633,7 +1633,8 @@ private function generateMethodName($id)
16331633
return $this->serviceIdToMethodNameMap[$id];
16341634
}
16351635

1636-
$name = Container::camelize($id);
1636+
$i = strrpos($id, '\\');
1637+
$name = Container::camelize(false !== $i && isset($id[1 + $i]) ? substr($id, 1 + $i) : $id);
16371638
$name = preg_replace('/[^a-zA-Z0-9_\x7f-\xff]/', '', $name);
16381639
$methodName = 'get'.$name.'Service';
16391640
$suffix = 1;

src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container33.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,9 @@
44

55
use Symfony\Component\DependencyInjection\ContainerBuilder;
66

7-
if (!class_exists(Foo::class, false)) {
8-
class Foo
9-
{
10-
}
11-
}
12-
137
$container = new ContainerBuilder();
148

15-
$container->register(Foo::class);
9+
$container->register(\Foo\Foo::class);
10+
$container->register(\Bar\Foo::class);
1611

1712
return $container;

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services33.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ public function __construct()
2828
{
2929
$this->services = array();
3030
$this->normalizedIds = array(
31-
'symfony\\component\\dependencyinjection\\tests\\fixtures\\container33\\foo' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\Container33\\Foo',
31+
'bar\\foo' => 'Bar\\Foo',
32+
'foo\\foo' => 'Foo\\Foo',
3233
);
3334
$this->methodMap = array(
34-
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\Container33\\Foo' => 'getSymfony_Component_DependencyInjection_Tests_Fixtures_Container33_FooService',
35+
'Bar\\Foo' => 'getFooService',
36+
'Foo\\Foo' => 'getFoo2Service',
3537
);
3638

3739
$this->aliases = array();
@@ -64,12 +66,22 @@ public function isFrozen()
6466
}
6567

6668
/**
67-
* Gets the public 'Symfony\Component\DependencyInjection\Tests\Fixtures\Container33\Foo' shared service.
69+
* Gets the public 'Bar\Foo' shared service.
6870
*
69-
* @return \Symfony\Component\DependencyInjection\Tests\Fixtures\Container33\Foo
71+
* @return \Bar\Foo
7072
*/
71-
protected function getSymfony_Component_DependencyInjection_Tests_Fixtures_Container33_FooService()
73+
protected function getFooService()
7274
{
73-
return $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\Container33\Foo'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\Container33\Foo();
75+
return $this->services['Bar\Foo'] = new \Bar\Foo();
76+
}
77+
78+
/**
79+
* Gets the public 'Foo\Foo' shared service.
80+
*
81+
* @return \Foo\Foo
82+
*/
83+
protected function getFoo2Service()
84+
{
85+
return $this->services['Foo\Foo'] = new \Foo\Foo();
7486
}
7587
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_subscriber.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public function __construct()
3232
'symfony\\component\\dependencyinjection\\tests\\fixtures\\testservicesubscriber' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber',
3333
);
3434
$this->methodMap = array(
35-
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber' => 'getSymfony_Component_DependencyInjection_Tests_Fixtures_TestServiceSubscriberService',
36-
'autowired.Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition' => 'getAutowired_Symfony_Component_DependencyInjection_Tests_Fixtures_CustomDefinitionService',
35+
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber' => 'getTestServiceSubscriberService',
36+
'autowired.Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition' => 'getCustomDefinitionService',
3737
'foo_service' => 'getFooServiceService',
3838
);
3939
$this->privates = array(
@@ -74,7 +74,7 @@ public function isFrozen()
7474
*
7575
* @return \Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber
7676
*/
77-
protected function getSymfony_Component_DependencyInjection_Tests_Fixtures_TestServiceSubscriberService()
77+
protected function getTestServiceSubscriberService()
7878
{
7979
return $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber();
8080
}
@@ -87,13 +87,13 @@ protected function getSymfony_Component_DependencyInjection_Tests_Fixtures_TestS
8787
protected function getFooServiceService()
8888
{
8989
return $this->services['foo_service'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber(new \Symfony\Component\DependencyInjection\ServiceLocator(array('Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition' => function () {
90-
$f = function (\Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition $v) { return $v; }; return $f(${($_ = isset($this->services['autowired.Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition']) ? $this->services['autowired.Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition'] : $this->getAutowired_Symfony_Component_DependencyInjection_Tests_Fixtures_CustomDefinitionService()) && false ?: '_'});
90+
$f = function (\Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition $v) { return $v; }; return $f(${($_ = isset($this->services['autowired.Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition']) ? $this->services['autowired.Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition'] : $this->getCustomDefinitionService()) && false ?: '_'});
9191
}, 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber' => function () {
9292
$f = function (\Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber $v) { return $v; }; return $f(${($_ = isset($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber']) ? $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber'] : $this->get('Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber')) && false ?: '_'});
9393
}, 'bar' => function () {
9494
$f = function (\Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition $v) { return $v; }; return $f(${($_ = isset($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber']) ? $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber'] : $this->get('Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber')) && false ?: '_'});
9595
}, 'baz' => function () {
96-
$f = function (\Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition $v) { return $v; }; return $f(${($_ = isset($this->services['autowired.Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition']) ? $this->services['autowired.Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition'] : $this->getAutowired_Symfony_Component_DependencyInjection_Tests_Fixtures_CustomDefinitionService()) && false ?: '_'});
96+
$f = function (\Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition $v) { return $v; }; return $f(${($_ = isset($this->services['autowired.Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition']) ? $this->services['autowired.Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition'] : $this->getCustomDefinitionService()) && false ?: '_'});
9797
})));
9898
}
9999

@@ -102,7 +102,7 @@ protected function getFooServiceService()
102102
*
103103
* @return \Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition
104104
*/
105-
protected function getAutowired_Symfony_Component_DependencyInjection_Tests_Fixtures_CustomDefinitionService()
105+
protected function getCustomDefinitionService()
106106
{
107107
return $this->services['autowired.Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition();
108108
}

0 commit comments

Comments
 (0)