Skip to content

Commit 58544c9

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: (95 commits) [DependencyInjection] provide better error message when using deprecated configuration options [console][TableCell] get cell width without decoration. Improve the config validation in TwigBundle [VarDumper] Changed tooltip to expand-all keybinding in OS X [Bridge\PhpUnit] Fix composer installed phpunit detection [VarDumper] Fix generic casters calling order [2.7][SecurityBundle] Remove SecurityContext from Compile [WebProfilerBundle][logger] added missing deprecation message. Fix profiler CSS [Security][Acl] enforce string identifiers [FrameworkBundle] make `templating.helper.router` service available again for BC reasons [BrowserKit] Fix bug when uri starts with http. bumped Symfony version to 2.7.1 updated VERSION for 2.7.0 updated CHANGELOG for 2.7.0 bumped Symfony version to 2.6.10 updated VERSION for 2.6.9 updated CHANGELOG for 2.6.9 fixed tests bumped Symfony version to 2.3.31 ... Conflicts: src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig src/Symfony/Component/HttpKernel/Kernel.php src/Symfony/Component/Translation/Loader/JsonFileLoader.php
2 parents 90a7527 + 3cacf5d commit 58544c9

11 files changed

+94
-77
lines changed

Container.php

Lines changed: 56 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ class Container implements IntrospectableContainerInterface
7676
protected $scopeStacks = array();
7777
protected $loading = array();
7878

79+
private $underscoreMap = array('_' => '', '.' => '_', '\\' => '_');
80+
7981
/**
8082
* Constructor.
8183
*
@@ -211,7 +213,7 @@ public function set($id, $service, $scope = self::SCOPE_CONTAINER)
211213

212214
$this->services[$id] = $service;
213215

214-
if (method_exists($this, $method = 'synchronize'.strtr($id, array('_' => '', '.' => '_', '\\' => '_')).'Service')) {
216+
if (method_exists($this, $method = 'synchronize'.strtr($id, $this->underscoreMap).'Service')) {
215217
$this->$method();
216218
}
217219

@@ -235,17 +237,20 @@ public function set($id, $service, $scope = self::SCOPE_CONTAINER)
235237
*/
236238
public function has($id)
237239
{
238-
$id = strtolower($id);
239-
240-
if ('service_container' === $id) {
241-
return true;
240+
for ($i = 2;;) {
241+
if ('service_container' === $id
242+
|| isset($this->aliases[$id])
243+
|| isset($this->services[$id])
244+
|| array_key_exists($id, $this->services)
245+
) {
246+
return true;
247+
}
248+
if (--$i && $id !== $lcId = strtolower($id)) {
249+
$id = $lcId;
250+
} else {
251+
return method_exists($this, 'get'.strtr($id, $this->underscoreMap).'Service');
252+
}
242253
}
243-
244-
return isset($this->services[$id])
245-
|| array_key_exists($id, $this->services)
246-
|| isset($this->aliases[$id])
247-
|| method_exists($this, 'get'.strtr($id, array('_' => '', '.' => '_', '\\' => '_')).'Service')
248-
;
249254
}
250255

251256
/**
@@ -273,10 +278,7 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE
273278
// available services. Service IDs are case insensitive, however since
274279
// this method can be called thousands of times during a request, avoid
275280
// calling strtolower() unless necessary.
276-
foreach (array(false, true) as $strtolower) {
277-
if ($strtolower) {
278-
$id = strtolower($id);
279-
}
281+
for ($i = 2;;) {
280282
if ('service_container' === $id) {
281283
return $this;
282284
}
@@ -287,57 +289,60 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE
287289
if (isset($this->services[$id]) || array_key_exists($id, $this->services)) {
288290
return $this->services[$id];
289291
}
290-
}
291292

292-
if (isset($this->loading[$id])) {
293-
throw new ServiceCircularReferenceException($id, array_keys($this->loading));
294-
}
293+
if (isset($this->loading[$id])) {
294+
throw new ServiceCircularReferenceException($id, array_keys($this->loading));
295+
}
295296

296-
if (isset($this->methodMap[$id])) {
297-
$method = $this->methodMap[$id];
298-
} elseif (method_exists($this, $method = 'get'.strtr($id, array('_' => '', '.' => '_', '\\' => '_')).'Service')) {
299-
// $method is set to the right value, proceed
300-
} else {
301-
if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior) {
302-
if (!$id) {
303-
throw new ServiceNotFoundException($id);
304-
}
297+
if (isset($this->methodMap[$id])) {
298+
$method = $this->methodMap[$id];
299+
} elseif (--$i && $id !== $lcId = strtolower($id)) {
300+
$id = $lcId;
301+
continue;
302+
} elseif (method_exists($this, $method = 'get'.strtr($id, $this->underscoreMap).'Service')) {
303+
// $method is set to the right value, proceed
304+
} else {
305+
if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior) {
306+
if (!$id) {
307+
throw new ServiceNotFoundException($id);
308+
}
305309

306-
$alternatives = array();
307-
foreach ($this->services as $key => $associatedService) {
308-
$lev = levenshtein($id, $key);
309-
if ($lev <= strlen($id) / 3 || false !== strpos($key, $id)) {
310-
$alternatives[] = $key;
310+
$alternatives = array();
311+
foreach ($this->services as $key => $associatedService) {
312+
$lev = levenshtein($id, $key);
313+
if ($lev <= strlen($id) / 3 || false !== strpos($key, $id)) {
314+
$alternatives[] = $key;
315+
}
311316
}
317+
318+
throw new ServiceNotFoundException($id, null, null, $alternatives);
312319
}
313320

314-
throw new ServiceNotFoundException($id, null, null, $alternatives);
321+
return;
315322
}
316323

317-
return;
318-
}
324+
$this->loading[$id] = true;
319325

320-
$this->loading[$id] = true;
326+
try {
327+
$service = $this->$method();
328+
} catch (\Exception $e) {
329+
unset($this->loading[$id]);
321330

322-
try {
323-
$service = $this->$method();
324-
} catch (\Exception $e) {
325-
unset($this->loading[$id]);
331+
if (array_key_exists($id, $this->services)) {
332+
unset($this->services[$id]);
333+
}
326334

327-
if (array_key_exists($id, $this->services)) {
328-
unset($this->services[$id]);
329-
}
335+
if ($e instanceof InactiveScopeException && self::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) {
336+
return;
337+
}
330338

331-
if ($e instanceof InactiveScopeException && self::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) {
332-
return;
339+
throw $e;
333340
}
334341

335-
throw $e;
336-
}
337-
338-
unset($this->loading[$id]);
342+
unset($this->loading[$id]);
339343

340-
return $service;
344+
return $service;
345+
}
341346
}
342347

343348
/**

Definition.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function getFactory()
9898
*/
9999
public function setFactoryClass($factoryClass)
100100
{
101-
trigger_error('The '.__METHOD__.' method is deprecated since version 2.6 and will be removed in 3.0. Use Definition::setFactory() instead.', E_USER_DEPRECATED);
101+
trigger_error(sprintf('%s(%s) is deprecated since version 2.6 and will be removed in 3.0. Use Definition::setFactory() instead.', __METHOD__, $factoryClass), E_USER_DEPRECATED);
102102

103103
$this->factoryClass = $factoryClass;
104104

@@ -134,7 +134,7 @@ public function getFactoryClass($triggerDeprecationError = true)
134134
*/
135135
public function setFactoryMethod($factoryMethod)
136136
{
137-
trigger_error('The '.__METHOD__.' method is deprecated since version 2.6 and will be removed in 3.0. Use Definition::setFactory() instead.', E_USER_DEPRECATED);
137+
trigger_error(sprintf('%s(%s) is deprecated since version 2.6 and will be removed in 3.0. Use Definition::setFactory() instead.', __METHOD__, $factoryMethod), E_USER_DEPRECATED);
138138

139139
$this->factoryMethod = $factoryMethod;
140140

@@ -205,7 +205,7 @@ public function getFactoryMethod($triggerDeprecationError = true)
205205
*/
206206
public function setFactoryService($factoryService)
207207
{
208-
trigger_error('The '.__METHOD__.' method is deprecated since version 2.6 and will be removed in 3.0. Use Definition::setFactory() instead.', E_USER_DEPRECATED);
208+
trigger_error(sprintf('%s(%s) is deprecated since version 2.6 and will be removed in 3.0. Use Definition::setFactory() instead.', __METHOD__, $factoryService), E_USER_DEPRECATED);
209209

210210
$this->factoryService = $factoryService;
211211

Loader/XmlFileLoader.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,11 @@ private function parseDefinitions(\DOMDocument $xml, $file)
126126
* Parses an individual Definition.
127127
*
128128
* @param \DOMElement $service
129+
* @param string $file
129130
*
130131
* @return Definition|null
131132
*/
132-
private function parseDefinition(\DOMElement $service)
133+
private function parseDefinition(\DOMElement $service, $file)
133134
{
134135
if ($alias = $service->getAttribute('alias')) {
135136
$public = true;
@@ -149,13 +150,22 @@ private function parseDefinition(\DOMElement $service)
149150

150151
foreach (array('class', 'scope', 'public', 'factory-class', 'factory-method', 'factory-service', 'synthetic', 'lazy', 'abstract') as $key) {
151152
if ($value = $service->getAttribute($key)) {
153+
if (in_array($key, array('factory-class', 'factory-method', 'factory-service'))) {
154+
trigger_error(sprintf('The "%s" attribute in file "%s" is deprecated since version 2.6 and will be removed in 3.0. Use the "factory" element instead.', $key, $file), E_USER_DEPRECATED);
155+
}
152156
$method = 'set'.str_replace('-', '', $key);
153157
$definition->$method(XmlUtils::phpize($value));
154158
}
155159
}
156160

157161
if ($value = $service->getAttribute('synchronized')) {
158-
$definition->setSynchronized(XmlUtils::phpize($value), 'request' !== (string) $service->getAttribute('id'));
162+
$triggerDeprecation = 'request' !== (string) $service->getAttribute('id');
163+
164+
if ($triggerDeprecation) {
165+
trigger_error(sprintf('The "synchronized" attribute in file "%s" is deprecated since version 2.7 and will be removed in 3.0.', $file), E_USER_DEPRECATED);
166+
}
167+
168+
$definition->setSynchronized(XmlUtils::phpize($value), $triggerDeprecation);
159169
}
160170

161171
if ($files = $this->getChildren($service, 'file')) {
@@ -173,7 +183,7 @@ private function parseDefinition(\DOMElement $service)
173183
$factoryService = $this->getChildren($factory, 'service');
174184

175185
if (isset($factoryService[0])) {
176-
$class = $this->parseDefinition($factoryService[0]);
186+
$class = $this->parseDefinition($factoryService[0], $file);
177187
} elseif ($childService = $factory->getAttribute('service')) {
178188
$class = new Reference($childService, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false);
179189
} else {
@@ -192,7 +202,7 @@ private function parseDefinition(\DOMElement $service)
192202
$configuratorService = $this->getChildren($configurator, 'service');
193203

194204
if (isset($configuratorService[0])) {
195-
$class = $this->parseDefinition($configuratorService[0]);
205+
$class = $this->parseDefinition($configuratorService[0], $file);
196206
} elseif ($childService = $configurator->getAttribute('service')) {
197207
$class = new Reference($childService, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false);
198208
} else {
@@ -233,7 +243,7 @@ private function parseDefinition(\DOMElement $service)
233243
}
234244

235245
/**
236-
* Parses a XML file to a \DOMDocument
246+
* Parses a XML file to a \DOMDocument.
237247
*
238248
* @param string $file Path to a file
239249
*
@@ -392,7 +402,7 @@ private function getArgumentsAsPhp(\DOMElement $node, $name, $lowercase = true)
392402
}
393403

394404
/**
395-
* Get child elements by name
405+
* Get child elements by name.
396406
*
397407
* @param \DOMNode $node
398408
* @param mixed $name

Loader/YamlFileLoader.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ private function parseDefinition($id, $service, $file)
172172
}
173173

174174
if (isset($service['synchronized'])) {
175+
trigger_error(sprintf('The "synchronized" key in file "%s" is deprecated since version 2.7 and will be removed in 3.0.', $file), E_USER_DEPRECATED);
175176
$definition->setSynchronized($service['synchronized'], 'request' !== $id);
176177
}
177178

@@ -201,14 +202,17 @@ private function parseDefinition($id, $service, $file)
201202
}
202203

203204
if (isset($service['factory_class'])) {
205+
trigger_error(sprintf('The "factory_class" key in file "%s" is deprecated since version 2.6 and will be removed in 3.0. Use "factory" instead.', $file), E_USER_DEPRECATED);
204206
$definition->setFactoryClass($service['factory_class']);
205207
}
206208

207209
if (isset($service['factory_method'])) {
210+
trigger_error(sprintf('The "factory_method" key in file "%s" is deprecated since version 2.6 and will be removed in 3.0. Use "factory" instead.', $file), E_USER_DEPRECATED);
208211
$definition->setFactoryMethod($service['factory_method']);
209212
}
210213

211214
if (isset($service['factory_service'])) {
215+
trigger_error(sprintf('The "factory_service" key in file "%s" is deprecated since version 2.6 and will be removed in 3.0. Use "factory" instead.', $file), E_USER_DEPRECATED);
212216
$definition->setFactoryService($service['factory_service']);
213217
}
214218

Tests/ContainerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ public function testEnterLeaveCurrentScope()
322322

323323
$container->enterScope('foo');
324324
$scoped2 = $container->get('scoped');
325-
$scoped3 = $container->get('scoped');
325+
$scoped3 = $container->get('SCOPED');
326326
$scopedFoo2 = $container->get('scoped_foo');
327327

328328
$container->leaveScope('foo');

Tests/Fixtures/xml/legacy-services6.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
<services>
77
<service id="constructor" class="FooClass" factory-method="getInstance" />
88
<service id="factory_service" factory-method="getInstance" factory-service="baz_factory" />
9+
<service id="request" class="Request" synthetic="true" synchronized="true" lazy="true"/>
910
</services>
1011
</container>

Tests/Fixtures/xml/services6.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
</service>
4848
<service id="alias_for_foo" alias="foo" />
4949
<service id="another_alias_for_foo" alias="foo" public="false" />
50-
<service id="request" class="Request" synthetic="true" synchronized="true" lazy="true"/>
5150
<service id="decorator_service" decorates="decorated" />
5251
<service id="decorator_service_with_name" decorates="decorated" decoration-inner-name="decorated.pif-pouf"/>
5352
<service id="new_factory1" class="FooBarClass">
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
services:
22
constructor: { class: FooClass, factory_method: getInstance }
33
factory_service: { class: BazClass, factory_method: getInstance, factory_service: baz_factory }
4+
request:
5+
class: Request
6+
synthetic: true
7+
synchronized: true
8+
lazy: true

Tests/Fixtures/yaml/services6.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ services:
2323
another_alias_for_foo:
2424
alias: foo
2525
public: false
26-
request:
27-
class: Request
28-
synthetic: true
29-
synchronized: true
30-
lazy: true
3126
decorator_service:
3227
decorates: decorated
3328
decorator_service_with_name:

Tests/Loader/XmlFileLoaderTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ public function testLegacyLoadServices()
206206
$this->assertNull($services['factory_service']->getClass());
207207
$this->assertEquals('baz_factory', $services['factory_service']->getFactoryService());
208208
$this->assertEquals('getInstance', $services['factory_service']->getFactoryMethod());
209+
$this->assertTrue($services['request']->isSynthetic(), '->load() parses the synthetic flag');
210+
$this->assertTrue($services['request']->isSynchronized(), '->load() parses the synchronized flag');
211+
$this->assertTrue($services['request']->isLazy(), '->load() parses the lazy flag');
212+
$this->assertNull($services['request']->getDecoratedService());
209213
}
210214

211215
public function testLoadServices()
@@ -231,10 +235,6 @@ public function testLoadServices()
231235
$this->assertEquals(array(new Reference('baz', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false), 'getClass'), $services['new_factory2']->getFactory(), '->load() parses the factory tag');
232236
$this->assertEquals(array('BazClass', 'getInstance'), $services['new_factory3']->getFactory(), '->load() parses the factory tag');
233237

234-
$this->assertTrue($services['request']->isSynthetic(), '->load() parses the synthetic flag');
235-
$this->assertTrue($services['request']->isSynchronized(false), '->load() parses the synchronized flag');
236-
$this->assertTrue($services['request']->isLazy(), '->load() parses the lazy flag');
237-
238238
$aliases = $container->getAliases();
239239
$this->assertTrue(isset($aliases['alias_for_foo']), '->load() parses <service> elements');
240240
$this->assertEquals('foo', (string) $aliases['alias_for_foo'], '->load() parses aliases');
@@ -243,7 +243,6 @@ public function testLoadServices()
243243
$this->assertEquals('foo', (string) $aliases['another_alias_for_foo']);
244244
$this->assertFalse($aliases['another_alias_for_foo']->isPublic());
245245

246-
$this->assertNull($services['request']->getDecoratedService());
247246
$this->assertEquals(array('decorated', null), $services['decorator_service']->getDecoratedService());
248247
$this->assertEquals(array('decorated', 'decorated.pif-pouf'), $services['decorator_service_with_name']->getDecoratedService());
249248
}

0 commit comments

Comments
 (0)