Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[DependencyInjection] Fix self-referenced 'service_container' service #14445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public function __construct()
$this->scopedServices =
$this->scopeStacks = array();

$this->set('service_container', $this);

$this->scopes = array();
$this->scopeChildren = array();
}
Expand Down
20 changes: 7 additions & 13 deletions 20 src/Symfony/Component/DependencyInjection/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ class Container implements IntrospectableContainerInterface
public function __construct(ParameterBagInterface $parameterBag = null)
{
$this->parameterBag = $parameterBag ?: new ParameterBag();

$this->set('service_container', $this);
}

/**
Expand Down Expand Up @@ -197,12 +195,10 @@ public function set($id, $service, $scope = self::SCOPE_CONTAINER)

$id = strtolower($id);

if ('service_container' === $id) {
// BC: 'service_container' is no longer a self-reference but always
// $this, so ignore this call.
// @todo Throw InvalidArgumentException in next major release.
return;
if (self::CONTAINER_ID === $id) {
throw new InvalidArgumentException(sprintf('You cannot overwrite the "%s" service.', self::CONTAINER_ID));
}

if (self::SCOPE_CONTAINER !== $scope) {
if (!isset($this->scopedServices[$scope])) {
throw new RuntimeException(sprintf('You cannot set service "%s" of inactive scope.', $id));
Expand Down Expand Up @@ -239,7 +235,7 @@ public function has($id)
{
$id = strtolower($id);

if ('service_container' === $id) {
if (self::CONTAINER_ID === $id) {
return true;
}

Expand Down Expand Up @@ -280,7 +276,7 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE
if ($strtolower) {
$id = strtolower($id);
}
if ('service_container' === $id) {
if (self::CONTAINER_ID === $id) {
return $this;
}
if (isset($this->aliases[$id])) {
Expand Down Expand Up @@ -354,9 +350,7 @@ public function initialized($id)
{
$id = strtolower($id);

if ('service_container' === $id) {
// BC: 'service_container' was a synthetic service previously.
// @todo Change to false in next major release.
if (self::CONTAINER_ID === $id) {
return true;
}

Expand All @@ -381,7 +375,7 @@ public function getServiceIds()
$ids[] = self::underscore($match[1]);
}
}
$ids[] = 'service_container';
$ids[] = self::CONTAINER_ID;

return array_unique(array_merge($ids, array_keys($this->services)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface ContainerInterface
const EXCEPTION_ON_INVALID_REFERENCE = 1;
const NULL_ON_INVALID_REFERENCE = 2;
const IGNORE_ON_INVALID_REFERENCE = 3;
const CONTAINER_ID = 'service_container';
const SCOPE_CONTAINER = 'container';
const SCOPE_PROTOTYPE = 'prototype';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private function findNodes()
}

if (!$container->hasDefinition($id)) {
$class = ('service_container' === $id) ? get_class($this->container) : get_class($service);
$class = (ContainerInterface::CONTAINER_ID === $id) ? get_class($this->container) : get_class($service);
$nodes[$id] = array('class' => str_replace('\\', '\\\\', $class), 'attributes' => $this->options['node.instance']);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ private function addServiceLocalTempVariables($cId, $definition)

$code = '';
foreach ($calls as $id => $callCount) {
if ('service_container' === $id || $id === $cId) {
if (ContainerInterface::CONTAINER_ID === $id || $id === $cId) {
continue;
}

Expand Down Expand Up @@ -905,8 +905,6 @@ public function __construct()
\$this->scopedServices =
\$this->scopeStacks = array();

\$this->set('service_container', \$this);

EOF;

$code .= "\n";
Expand Down Expand Up @@ -1431,7 +1429,7 @@ public function addExpressionLanguageProvider(ExpressionFunctionProviderInterfac
*/
private function getServiceCall($id, Reference $reference = null)
{
if ('service_container' === $id) {
if (ContainerInterface::CONTAINER_ID === $id) {
return '$this';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\ExpressionLanguage\Expression;

$container = new ContainerBuilder();
$container->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ public function __construct()
$this->scopedServices =
$this->scopeStacks = array();

$this->set('service_container', $this);

$this->scopes = array();
$this->scopeChildren = array();
$this->methodMap = array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public function __construct()
$this->scopedServices =
$this->scopeStacks = array();

$this->set('service_container', $this);

$this->scopes = array();
$this->scopeChildren = array();
$this->methodMap = array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ public function __construct()
$this->scopedServices =
$this->scopeStacks = array();

$this->set('service_container', $this);

$this->scopes = array();
$this->scopeChildren = array();
$this->methodMap = array(
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.