Skip to content

Commit 3831103

Browse files
committed
Merge branch '3.0' into 3.1
* 3.0: [Yaml] fix exception contexts People - person singularization [Yaml] properly handle unindented collections [Serializer] Add test for ignored attributes during denormalization chomp newlines only at the end of YAML documents Fixed server status command when port has been omitted Update UPGRADE FROM 2.x to 3.0 fix removed commands wording in upgrade file Catch \Throwable Catch \Throwable [DependencyInjection] Avoid generating call_user_func in more cases [Validator] Support for DateTimeImmutable [FrameworkBundle] update upgrade instructions Use levenshtein level for better Bundle matching [WebProfilerBundle] Fix CORS ajax security issues remove methods that were needed for PHP 5.3 [DX][DI] Make Autowiring exceptions more future friendly
2 parents 972fcf5 + 015cb81 commit 3831103

File tree

9 files changed

+159
-3
lines changed

9 files changed

+159
-3
lines changed

Compiler/AutowirePass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public function process(ContainerBuilder $container)
4545
$this->completeDefinition($id, $definition);
4646
}
4747
}
48-
} catch (\Error $e) {
4948
} catch (\Exception $e) {
49+
} catch (\Throwable $e) {
5050
}
5151

5252
spl_autoload_unregister($throwingAutoloader);
@@ -283,7 +283,7 @@ private function createAutowiredDefinition(\ReflectionClass $typeHint, $id)
283283

284284
try {
285285
$this->completeDefinition($argumentId, $argumentDefinition);
286-
} catch (\RuntimeException $e) {
286+
} catch (RuntimeException $e) {
287287
$classOrInterface = $typeHint->isInterface() ? 'interface' : 'class';
288288
$message = sprintf('Unable to autowire argument of type "%s" for the service "%s". No services were found matching this %s and it cannot be auto-registered.', $typeHint->name, $id, $classOrInterface);
289289
throw new RuntimeException($message, 0, $e);

Dumper/PhpDumper.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,10 @@ private function addServiceConfigurator($id, $definition, $variableName = 'insta
542542
return sprintf(" %s::%s(\$%s);\n", $this->dumpLiteralClass($class), $callable[1], $variableName);
543543
}
544544

545+
if (0 === strpos($class, 'new ')) {
546+
return sprintf(" (%s)->%s(\$%s);\n", $this->dumpValue($callable[0]), $callable[1], $variableName);
547+
}
548+
545549
return sprintf(" call_user_func(array(%s, '%s'), \$%s);\n", $this->dumpValue($callable[0]), $callable[1], $variableName);
546550
}
547551

@@ -723,6 +727,10 @@ private function addNewInstance(Definition $definition, $return, $instantiation,
723727
return sprintf(" $return{$instantiation}%s::%s(%s);\n", $this->dumpLiteralClass($class), $callable[1], $arguments ? implode(', ', $arguments) : '');
724728
}
725729

730+
if (0 === strpos($class, 'new ')) {
731+
return sprintf(" $return{$instantiation}(%s)->%s(%s);\n", $this->dumpValue($callable[0]), $callable[1], $arguments ? implode(', ', $arguments) : '');
732+
}
733+
726734
return sprintf(" $return{$instantiation}call_user_func(array(%s, '%s')%s);\n", $this->dumpValue($callable[0]), $callable[1], $arguments ? ', '.implode(', ', $arguments) : '');
727735
}
728736

Tests/Fixtures/containers/container9.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@
7878
->register('configured_service', 'stdClass')
7979
->setConfigurator(array(new Reference('configurator_service'), 'configureStdClass'))
8080
;
81+
$container
82+
->register('configurator_service_simple', 'ConfClass')
83+
->addArgument('bar')
84+
->setPublic(false)
85+
;
86+
$container
87+
->register('configured_service_simple', 'stdClass')
88+
->setConfigurator(array(new Reference('configurator_service_simple'), 'configureStdClass'))
89+
;
8190
$container
8291
->register('decorated', 'stdClass')
8392
;
@@ -111,5 +120,14 @@
111120
->register('service_from_static_method', 'Bar\FooClass')
112121
->setFactory(array('Bar\FooClass', 'getInstance'))
113122
;
123+
$container
124+
->register('factory_simple', 'SimpleFactoryClass')
125+
->addArgument('foo')
126+
->setPublic(false)
127+
;
128+
$container
129+
->register('factory_service_simple', 'Bar')
130+
->setFactory(array(new Reference('factory_simple'), 'getInstance'))
131+
;
114132

115133
return $container;

Tests/Fixtures/graphviz/services9.dot

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ digraph sc {
1414
node_request [label="request\nRequest\n", shape=record, fillcolor="#eeeeee", style="filled"];
1515
node_configurator_service [label="configurator_service\nConfClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
1616
node_configured_service [label="configured_service\nstdClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
17+
node_configurator_service_simple [label="configurator_service_simple\nConfClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
18+
node_configured_service_simple [label="configured_service_simple\nstdClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
1719
node_decorated [label="decorated\nstdClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
1820
node_decorator_service [label="decorator_service\nstdClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
1921
node_decorator_service_with_name [label="decorator_service_with_name\nstdClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
@@ -22,6 +24,8 @@ digraph sc {
2224
node_factory_service [label="factory_service\nBar\n", shape=record, fillcolor="#eeeeee", style="filled"];
2325
node_new_factory_service [label="new_factory_service\nFooBarBaz\n", shape=record, fillcolor="#eeeeee", style="filled"];
2426
node_service_from_static_method [label="service_from_static_method\nBar\\FooClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
27+
node_factory_simple [label="factory_simple\nSimpleFactoryClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
28+
node_factory_service_simple [label="factory_service_simple\nBar\n", shape=record, fillcolor="#eeeeee", style="filled"];
2529
node_service_container [label="service_container\nSymfony\\Component\\DependencyInjection\\ContainerBuilder\n", shape=record, fillcolor="#9999ff", style="filled"];
2630
node_foo2 [label="foo2\n\n", shape=record, fillcolor="#ff9999", style="filled"];
2731
node_foo3 [label="foo3\n\n", shape=record, fillcolor="#ff9999", style="filled"];

Tests/Fixtures/php/services19.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct()
4040
*/
4141
protected function getServiceFromAnonymousFactoryService()
4242
{
43-
return $this->services['service_from_anonymous_factory'] = call_user_func(array(new \Bar\FooClass(), 'getInstance'));
43+
return $this->services['service_from_anonymous_factory'] = (new \Bar\FooClass())->getInstance();
4444
}
4545

4646
/**

Tests/Fixtures/php/services9.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,16 @@ public function __construct()
2828
'bar' => 'getBarService',
2929
'baz' => 'getBazService',
3030
'configurator_service' => 'getConfiguratorServiceService',
31+
'configurator_service_simple' => 'getConfiguratorServiceSimpleService',
3132
'configured_service' => 'getConfiguredServiceService',
33+
'configured_service_simple' => 'getConfiguredServiceSimpleService',
3234
'decorated' => 'getDecoratedService',
3335
'decorator_service' => 'getDecoratorServiceService',
3436
'decorator_service_with_name' => 'getDecoratorServiceWithNameService',
3537
'deprecated_service' => 'getDeprecatedServiceService',
3638
'factory_service' => 'getFactoryServiceService',
39+
'factory_service_simple' => 'getFactoryServiceSimpleService',
40+
'factory_simple' => 'getFactorySimpleService',
3741
'foo' => 'getFooService',
3842
'foo.baz' => 'getFoo_BazService',
3943
'foo_bar' => 'getFooBarService',
@@ -104,6 +108,23 @@ protected function getConfiguredServiceService()
104108
return $instance;
105109
}
106110

111+
/**
112+
* Gets the 'configured_service_simple' service.
113+
*
114+
* This service is shared.
115+
* This method always returns the same instance of the service.
116+
*
117+
* @return \stdClass A stdClass instance.
118+
*/
119+
protected function getConfiguredServiceSimpleService()
120+
{
121+
$this->services['configured_service_simple'] = $instance = new \stdClass();
122+
123+
$this->get('configurator_service_simple')->configureStdClass($instance);
124+
125+
return $instance;
126+
}
127+
107128
/**
108129
* Gets the 'decorated' service.
109130
*
@@ -173,6 +194,19 @@ protected function getFactoryServiceService()
173194
return $this->services['factory_service'] = $this->get('foo.baz')->getInstance();
174195
}
175196

197+
/**
198+
* Gets the 'factory_service_simple' service.
199+
*
200+
* This service is shared.
201+
* This method always returns the same instance of the service.
202+
*
203+
* @return \Bar A Bar instance.
204+
*/
205+
protected function getFactoryServiceSimpleService()
206+
{
207+
return $this->services['factory_service_simple'] = $this->get('factory_simple')->getInstance();
208+
}
209+
176210
/**
177211
* Gets the 'foo' service.
178212
*
@@ -334,6 +368,40 @@ protected function getConfiguratorServiceService()
334368
return $instance;
335369
}
336370

371+
/**
372+
* Gets the 'configurator_service_simple' service.
373+
*
374+
* This service is shared.
375+
* This method always returns the same instance of the service.
376+
*
377+
* This service is private.
378+
* If you want to be able to request this service from the container directly,
379+
* make it public, otherwise you might end up with broken code.
380+
*
381+
* @return \ConfClass A ConfClass instance.
382+
*/
383+
protected function getConfiguratorServiceSimpleService()
384+
{
385+
return $this->services['configurator_service_simple'] = new \ConfClass('bar');
386+
}
387+
388+
/**
389+
* Gets the 'factory_simple' service.
390+
*
391+
* This service is shared.
392+
* This method always returns the same instance of the service.
393+
*
394+
* This service is private.
395+
* If you want to be able to request this service from the container directly,
396+
* make it public, otherwise you might end up with broken code.
397+
*
398+
* @return \SimpleFactoryClass A SimpleFactoryClass instance.
399+
*/
400+
protected function getFactorySimpleService()
401+
{
402+
return $this->services['factory_simple'] = new \SimpleFactoryClass('foo');
403+
}
404+
337405
/**
338406
* Gets the 'inlined' service.
339407
*

Tests/Fixtures/php/services9_compiled.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ public function __construct()
3030
'bar' => 'getBarService',
3131
'baz' => 'getBazService',
3232
'configured_service' => 'getConfiguredServiceService',
33+
'configured_service_simple' => 'getConfiguredServiceSimpleService',
3334
'decorator_service' => 'getDecoratorServiceService',
3435
'decorator_service_with_name' => 'getDecoratorServiceWithNameService',
3536
'deprecated_service' => 'getDeprecatedServiceService',
3637
'factory_service' => 'getFactoryServiceService',
38+
'factory_service_simple' => 'getFactoryServiceSimpleService',
3739
'foo' => 'getFooService',
3840
'foo.baz' => 'getFoo_BazService',
3941
'foo_bar' => 'getFooBarService',
@@ -114,6 +116,23 @@ protected function getConfiguredServiceService()
114116
return $instance;
115117
}
116118

119+
/**
120+
* Gets the 'configured_service_simple' service.
121+
*
122+
* This service is shared.
123+
* This method always returns the same instance of the service.
124+
*
125+
* @return \stdClass A stdClass instance.
126+
*/
127+
protected function getConfiguredServiceSimpleService()
128+
{
129+
$this->services['configured_service_simple'] = $instance = new \stdClass();
130+
131+
(new \ConfClass('bar'))->configureStdClass($instance);
132+
133+
return $instance;
134+
}
135+
117136
/**
118137
* Gets the 'decorator_service' service.
119138
*
@@ -170,6 +189,19 @@ protected function getFactoryServiceService()
170189
return $this->services['factory_service'] = $this->get('foo.baz')->getInstance();
171190
}
172191

192+
/**
193+
* Gets the 'factory_service_simple' service.
194+
*
195+
* This service is shared.
196+
* This method always returns the same instance of the service.
197+
*
198+
* @return \Bar A Bar instance.
199+
*/
200+
protected function getFactoryServiceSimpleService()
201+
{
202+
return $this->services['factory_service_simple'] = (new \SimpleFactoryClass('foo'))->getInstance();
203+
}
204+
173205
/**
174206
* Gets the 'foo' service.
175207
*

Tests/Fixtures/xml/services9.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@
8484
<service id="configured_service" class="stdClass">
8585
<configurator service="configurator_service" method="configureStdClass"/>
8686
</service>
87+
<service id="configurator_service_simple" class="ConfClass" public="false">
88+
<argument>bar</argument>
89+
</service>
90+
<service id="configured_service_simple" class="stdClass">
91+
<configurator service="configurator_service_simple" method="configureStdClass"/>
92+
</service>
8793
<service id="decorated" class="stdClass"/>
8894
<service id="decorator_service" class="stdClass" decorates="decorated"/>
8995
<service id="decorator_service_with_name" class="stdClass" decorates="decorated" decoration-inner-name="decorated.pif-pouf"/>
@@ -103,6 +109,12 @@
103109
<service id="service_from_static_method" class="Bar\FooClass">
104110
<factory class="Bar\FooClass" method="getInstance"/>
105111
</service>
112+
<service id="factory_simple" class="SimpleFactoryClass" public="false">
113+
<argument>foo</argument>
114+
</service>
115+
<service id="factory_service_simple" class="Bar">
116+
<factory service="factory_simple" method="getInstance"/>
117+
</service>
106118
<service id="alias_for_foo" alias="foo"/>
107119
<service id="alias_for_alias" alias="foo"/>
108120
</services>

Tests/Fixtures/yaml/services9.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ services:
6767
configured_service:
6868
class: stdClass
6969
configurator: ['@configurator_service', configureStdClass]
70+
configurator_service_simple:
71+
class: ConfClass
72+
public: false
73+
arguments: ['bar']
74+
configured_service_simple:
75+
class: stdClass
76+
configurator: ['@configurator_service_simple', configureStdClass]
7077
decorated:
7178
class: stdClass
7279
decorator_service:
@@ -93,5 +100,12 @@ services:
93100
service_from_static_method:
94101
class: Bar\FooClass
95102
factory: [Bar\FooClass, getInstance]
103+
factory_simple:
104+
class: SimpleFactoryClass
105+
public: false
106+
arguments: ['foo']
107+
factory_service_simple:
108+
class: Bar
109+
factory: ['@factory_simple', getInstance]
96110
alias_for_foo: '@foo'
97111
alias_for_alias: '@foo'

0 commit comments

Comments
 (0)