8000 Merge branch '2.0' into 2.1 · Ninir/symfony@f1d2fe9 · GitHub
[go: up one dir, main page]

Skip to content

Commit f1d2fe9

Browse files
committed
Merge branch '2.0' into 2.1
* 2.0: Restrict Monolog version to be in version <1.3 [Console] Make getTerminalWith & getTerminalHeight public [DependencyInjection] fixed PhpDumper optimizations when an inlined service depends on the current one indirectly [DependencyInjection] fixed PhpDumper when an inlined service definition has some properties [DependencyInjection] added some tests for PhpDumper when the container is compiled [DependencyInjection] fixed CS [Locale] Adjust `StubIntlDateFormatter` to have new methods added in PHP 5.5 [Locale] Fix failing `StubIntlDateFormatter` tests in PHP 5.5 [Locale] Fix failing `StubIntlDateFormatter` in PHP 5.5 [Form] Fix failing `MonthChoiceList` in PHP 5.5 Update .travis.yml Conflicts: src/Symfony/Bridge/Monolog/composer.json src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php src/Symfony/Component/Form/Extension/Core/ChoiceList/MonthChoiceList.php tests/Symfony/Tests/Component/DependencyInjection/Fixtures/yaml/services9.yml
2 parents 94aacec + 5258edb commit f1d2fe9

File tree

14 files changed

+671
-70
lines changed

14 files changed

+671
-70
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ php:
44
- 5.3.3
55
- 5.3
66
- 5.4
7+
- 5.5
8+
9+
matrix:
10+
allow_failures:
11+
- php: 5.5
712

813
before_script:
914
- COMPOSER_ROOT_VERSION=2.1.x-dev composer --prefer-source --dev install

src/Symfony/Bridge/Monolog/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"require": {
1919
"php": ">=5.3.3",
2020
"symfony/http-kernel": "2.1.*",
21-
"monolog/monolog": "1.*"
21+
"monolog/monolog": ">=1.0,<1.3-dev"
2222
},
2323
"autoload": {
2424
"psr-0": { "Symfony\\Bridge\\Monolog": "" }

src/Symfony/Component/Console/Application.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ public function renderException($e, $output)
846846
*
847847
* @return int|null
848848
*/
849-
protected function getTerminalWidth()
849+
public function getTerminalWidth()
850850
{
851851
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
852852
if ($ansicon = getenv('ANSICON')) {
@@ -868,7 +868,7 @@ protected function getTerminalWidth()
868868
*
869869
* @return int|null
870870
*/
871-
protected function getTerminalHeight()
871+
public function getTerminalHeight()
872872
{
873873
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
874874
if ($ansicon = getenv('ANSICON')) {

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

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ private function addServiceInlinedDefinitions($id, $definition)
203203
$nbOccurrences->offsetSet($definition, 1);
204204
} else {
205205
$i = $nbOccurrences->offsetGet($definition);
206-
$nbOccurrences->offsetSet($definition, $i+1);
206+
$nbOccurrences->offsetSet($definition, $i + 1);
207207
}
208208
}
209209

@@ -214,7 +214,7 @@ private function addServiceInlinedDefinitions($id, $definition)
214214
$processed->offsetSet($sDefinition);
215215

216216
$class = $this->dumpValue($sDefinition->getClass());
217-
if ($nbOccurrences->offsetGet($sDefinition) > 1 || count($sDefinition->getMethodCalls()) > 0 || $sDefinition->getProperties() || null !== $sDefinition->getConfigurator() || false !== strpos($class, '$')) {
217+
if ($nbOccurrences->offsetGet($sDefinition) > 1 || EF5E $sDefinition->getMethodCalls() || $sDefinition->getProperties() || null !== $sDefinition->getConfigurator() || false !== strpos($class, '$')) {
218218
$name = $this->getNextVariableName();
219219
$variableMap->offsetSet($sDefinition, new Variable($name));
220220

@@ -248,7 +248,7 @@ private function addServiceInlinedDefinitions($id, $definition)
248248
$code .= sprintf(" \$%s = new \\%s(%s);\n", $name, substr(str_replace('\\\\', '\\', $class), 1, -1), implode(', ', $arguments));
249249
}
250250

251-
if (!$this->hasReference($id, $sDefinition->getMethodCalls()) && !$this->hasReference($id, $sDefinition->getProperties())) {
251+
if (!$this->hasReference($id, $sDefinition->getMethodCalls(), true) && !$this->hasReference($id, $sDefinition->getProperties(), true)) {
252252
$code .= $this->addServiceMethodCalls(null, $sDefinition, $name);
253253
$code .= $this->addServiceProperties(null, $sDefinition, $name);
254254
$code .= $this->addServiceConfigurator(null, $sDefinition, $name);
@@ -417,16 +417,14 @@ private function addServiceInlinedDefinitionsSetup($id, $definition)
417417
}
418418
$processed->offsetSet($iDefinition);
419419

420-
if (!$this->hasReference($id, $iDefinition->getMethodCalls())) {
420+
if (!$this->hasReference($id, $iDefinition->getMethodCalls(), true) && !$this->hasReference($id, $iDefinition->getProperties(), true)) {
421421
continue;
422422
}
423423

424-
if ($iDefinition->getMethodCalls()) {
425-
$code .= $this->addServiceMethodCalls(null, $iDefinition, (string) $this->definitionVariables->offsetGet($iDefinition));
426-
}
427-
if ($iDefinition->getConfigurator()) {
428-
$code .= $this->addServiceConfigurator(null, $iDefinition, (string) $this->definitionVariables->offsetGet($iDefinition));
429-
}
424+
$name = (string) $this->definitionVariables->offsetGet($iDefinition);
425+
$code .= $this->addServiceMethodCalls(null, $iDefinition, $name);
426+
$code .= $this->addServiceProperties(null, $iDefinition, $name);
427+
$code .= $this->addServiceConfigurator(null, $iDefinition, $name);
430428
}
431429

432430
if ('' !== $code) {
@@ -963,17 +961,26 @@ private function getDefinitionsFromArguments(array $arguments)
963961
*
964962
* @return Boolean
965963
*/
966-
private function hasReference($id, array $arguments)
964+
private function hasReference($id, array $arguments, $deep = false)
967965
{
968966
foreach ($arguments as $argument) {
969967
if (is_array($argument)) {
970-
if ($this->hasReference($id, $argument)) {
968+
if ($this->hasReference($id, $argument, $deep)) {
971969
return true;
972970
}
973971
} elseif ($argument instanceof Reference) {
974972
if ($id === (string) $argument) {
975973
return true;
976974
}
975+
976+
if ($deep) {
977+
$service = $this->container->getDefinition((string) $argument);
978+
$arguments = array_merge($service->getMethodCalls(), $service->getArguments(), $service->getProperties());
979+
980+
if ($this->hasReference($id, $arguments, $deep)) {
981+
return true;
982+
}
983+
}
977984
}
978985
}
979986

src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,17 @@ public function testAddParameters()
103103

104104
public function testAddService()
105105
{
106+
// without compilation
106107
$container = include self::$fixturesPath.'/containers/container9.php';
107108
$dumper = new PhpDumper($container);
108109
$this->assertEquals(str_replace('%path%', str_replace('\\','\\\\',self::$fixturesPath.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR), file_get_contents(self::$fixturesPath.'/php/services9.php')), $dumper->dump(), '->dump() dumps services');
109110

111+
// with compilation
112+
$container = include self::$fixturesPath.'/containers/container9.php';
113+
$container->compile();
114+
$dumper = new PhpDumper($container);
115+
$this->assertEquals(str_replace('%path%', str_replace('\\','\\\\',self::$fixturesPath.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR), file_get_contents(self::$fixturesPath.'/php/services9_compiled.php')), $dumper->dump(), '->dump() dumps services');
116+
110117
$dumper = new PhpDumper($container = new ContainerBuilder());
111118
$container->register('foo', 'FooClass')->addArgument(new \stdClass());
112119
try {

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
addTag('foo', array('bar' => 'bar'))->
1515
setFactoryClass('FooClass')->
1616
setFactoryMethod('getInstance')->
17-
setArguments(array('foo', new Reference('foo.baz'), array('%foo%' => 'foo is %foo%', 'bar' => '%foo%'), true, new Reference('service_container')))->
17+
setArguments(array('foo', new Reference('foo.baz'), array('%foo%' => 'foo is %foo%', 'foobar' => '%foo%'), true, new Reference('service_container')))->
1818
setProperties(array('foo' => 'bar', 'moo' => new Reference('foo.baz')))->
19-
setScope('prototype')->
2019
addMethodCall('setBar', array(new Reference('bar')))->
2120
addMethodCall('initialize')->
2221
setConfigurator('sc_configure')
@@ -33,7 +32,10 @@
3332
setFactoryMethod('getInstance')->
3433
setConfigurator(array('%baz_class%', 'configureStatic1'))
3534
;
36-
$container->register('foo_bar', '%foo_class%');
35+
$container->
36+
register('foo_bar', '%foo_class%')->
37+
setScope('prototype')
38+
;
3739
$container->getParameterBag()->clear();
3840
$container->getParameterBag()->add(array(
3941
'baz_class' => 'BazClass',
@@ -50,9 +52,24 @@
5052
addMethodCall('setBar', array(new Reference('foobaz', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)))
5153
;
5254
$container->
53-
register('factory_service')->
55+
register('factory_service', 'Bar')->
5456
setFactoryService('foo.baz')->
5557
setFactoryMethod('getInstance')
5658
;
5759

60+
$container
61+
->register('foo_with_inline', 'Foo')
62+
->addMethodCall('setBar', array(new Reference('inlined')))
63+
;
64+
$container
65+
->register('inlined', 'Bar')
66+
->setProperty('pub', 'pub')
67+
->addMethodCall('setBaz', array(new Reference('baz')))
68+
->setPublic(false)
69+
;
70+
$container
71+
->register('baz', 'Baz')
72+
->addMethodCall('setFoo', array(new Reference('foo_with_inline')))
73+
;
74+
5875
return $container;

src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services9.dot

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ digraph sc {
33
node [fontsize="11" fontname="Arial" shape="record"];
44
edge [fontsize="9" fontname="Arial" color="grey" arrowhead="open" arrowsize="0.5"];
55

6-
node_foo [label="foo (alias_for_foo)\nFooClass\n", shape=record, fillcolor="#eeeeee", style="dotted"];
6+
node_foo [label="foo (alias_for_foo)\nFooClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
77
node_bar [label="bar\nFooClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
88
node_foo_baz [label="foo.baz\nBazClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
9-
node_foo_bar [label="foo_bar\nFooClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
9+
node_foo_bar [label="foo_bar\nFooClass\n", shape=record, fillcolor="#eeeeee", style="dotted"];
1010
node_method_call1 [label="method_call1\nFooClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
11-
node_factory_service [label="factory_service\n\n", shape=record, fillcolor="#eeeeee", style="filled"];
11+
node_factory_service [label="factory_service\nBar\n", shape=record, fillcolor="#eeeeee", style="filled"];
12+
node_foo_with_inline [label="foo_with_inline\nFoo\n", shape=record, fillcolor="#eeeeee", style="filled"];
13+
node_inlined [label="inlined\nBar\n", shape=record, fillcolor="#eeeeee", style="filled"];
14+
node_baz [label="baz\nBaz\n", shape=record, fillcolor="#eeeeee", style="filled"];
1215
node_service_container [label="service_container\nSymfony\\Component\\DependencyInjection\\ContainerBuilder\n", shape=record, fillcolor="#9999ff", style="filled"];
1316
node_foo2 [label="foo2\n\n", shape=record, fillcolor="#ff9999", style="filled"];
1417
node_foo3 [label="foo3\n\n", shape=record, fillcolor="#ff9999", style="filled"];
@@ -22,4 +25,7 @@ digraph sc {
2225
node_method_call1 -> node_foo2 [label="setBar()" style="dashed"];
2326
node_method_call1 -> node_foo3 [label="setBar()" style="dashed"];
2427
node_method_call1 -> node_foobaz [label="setBar()" style="dashed"];
28+
node_foo_with_inline -> node_inlined [label="setBar()" style="dashed"];
29+
node_inlined -> node_baz [label="setBaz()" style="dashed"];
30+
node_baz -> node_foo_with_inline [label="setFoo()" style="dashed"];
2531
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/classes.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,23 @@ function sc_configure($instance)
77

88
class BarClass
99
{
10+
protected $baz;
11+
12+
public function setBaz(BazClass $baz)
13+
{
14+
$this->baz = $baz;
15+
}
1016
}
1117

1218
class BazClass
1319
{
20+
protected $foo;
21+
22+
public function setFoo(Foo $foo)
23+
{
24+
$this->foo = $foo;
25+
}
26+
1427
public function configure($instance)
1528
{
1629
$instance->configure();

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

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,30 @@ protected function getBarService()
43 341A 43
return $instance;
4444
}
4545

46+
/**
47+
* Gets the 'baz' service.
48+
*
49+
* This service is shared.
50+
* This method always returns the same instance of the service.
51+
*
52+
* @return Baz A Baz instance.
53+
*/
54+
protected function getBazService()
55+
{
56+
$this->services['baz'] = $instance = new \Baz();
57+
58+
$instance->setFoo($this->get('foo_with_inline'));
59+
60+
return $instance;
61+
}
62+
4663
/**
4764
* Gets the 'factory_service' service.
4865
*
4966
* This service is shared.
5067
* This method always returns the same instance of the service.
5168
*
52-
* @return Object An instance returned by foo.baz::getInstance().
69+
* @return Bar A Bar instance.
5370
*/
5471
protected function getFactoryServiceService()
5572
{
@@ -59,13 +76,16 @@ protected function getFactoryServiceService()
5976
/**
6077
* Gets the 'foo' service.
6178
*
79+
* This service is shared.
80+
* This method always returns the same instance of the service.
81+
*
6282
* @return FooClass A FooClass instance.
6383
*/
6484
protected function getFooService()
6585
{
6686
$a = $this->get('foo.baz');
6787

68-
$instance = call_user_func(array('FooClass', 'getInstance'), 'foo', $a, array($this->getParameter('foo') => 'foo is '.$this->getParameter('foo'), 'bar' => $this->getParameter('foo')), true, $this);
88+
$this->services['foo'] = $instance = call_user_func(array('FooClass', 'getInstance'), 'foo', $a, array($this->getParameter('foo') => 'foo is '.$this->getParameter('foo'), 'foobar' => $this->getParameter('foo')), true, $this);
6989

7090
$instance->setBar($this->get('bar'));
7191
$instance->initialize();
@@ -96,16 +116,30 @@ protected function getFoo_BazService()
96116
/**
97117
* Gets the 'foo_bar' service.
98118
*
99-
* This service is shared.
100-
* This method always returns the same instance of the service.
101-
*
102119
* @return Object A %foo_class% instance.
103120
*/
104121
protected function getFooBarService()
105122
{
106123
$class = $this->getParameter('foo_class');
107124

108-
return $this->services['foo_bar'] = new $class();
125+
return new $class();
126+
}
127+
128+
/**
129+
* Gets the 'foo_with_inline' service.
130+
*
131+
* This service is shared.
132+
* This method always returns the same instance of the service.
133+
*
134+
* @return Foo A Foo instance.
135+
*/
136+
protected function getFooWithInlineService()
137+
{
138+
$this->services['foo_with_inline'] = $instance = new \Foo();
139+
140+
$instance->setBar($this->get('inlined'));
141+
142+
return $instance;
109143
}
110144

111145
/**
@@ -144,6 +178,28 @@ protected function getAliasForFooService()
144178
return $this->get('foo');
145179
}
146180

181+
/**
182+
* Gets the 'inlined' service.
183+
*
184+
* This service is shared.
185+
* This method always returns the same instance of the service.
186+
*
187+
* This service is private.
188+
* If you want to be able to request this service from the container directly,
189+
* make it public, otherwise you might end up with broken code.
190+
*
191+
* @return Bar A Bar instance.
192+
*/
193+
protected function getInlinedService()
194+
{
195+
$this->services['inlined'] = $instance = new \Bar();
196+
197+
$instance->setBaz($this->get('baz'));
198+
$instance->pub = 'pub';
199+
200+
return $instance;
201+
}
202+
147203
/**
148204
* Gets the default parameters.
149205
*

0 commit comments

Comments
 (0)
0