Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feature #22811 [DI] Remove deprecated case insensitive service ids (r…
…o0NL)

This PR was squashed before being merged into the 4.0-dev branch (closes #22811).

Discussion
----------

[DI] Remove deprecated case insensitive service ids

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | yes
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #... <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!--highly recommended for new features-->

See #21223

Commits
-------

63e26fc [DI] Remove deprecated case insensitive service ids
  • Loading branch information
nicolas-grekas committed Jul 11, 2017
2 parents 6db73d3 + 63e26fc commit a55cbf8
Show file tree
Hide file tree
Showing 21 changed files with 261 additions and 229 deletions.
3 changes: 0 additions & 3 deletions src/Symfony/Bridge/Doctrine/ManagerRegistry.php
Expand Up @@ -49,9 +49,6 @@ protected function resetService($name)
}
$manager->setProxyInitializer(\Closure::bind(
function (&$wrappedInstance, LazyLoadingInterface $manager) use ($name) {
if (isset($this->normalizedIds[$normalizedId = strtolower($name)])) {
$name = $this->normalizedIds[$normalizedId];
}
if (isset($this->aliases[$name])) {
$name = $this->aliases[$name];
}
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/DependencyInjection/CHANGELOG.md
Expand Up @@ -10,6 +10,7 @@ CHANGELOG
* removed `Container::isFrozen`
* removed support for dumping an ucompiled container in `PhpDumper`
* removed support for generating a dumped `Container` without populating the method map
* removed support for case insensitive service identifiers

3.4.0
-----
Expand Down
186 changes: 58 additions & 128 deletions src/Symfony/Component/DependencyInjection/Container.php
Expand Up @@ -26,26 +26,7 @@
*
* Services and parameters are simple key/pair stores.
*
* Parameter and service keys are case insensitive.
*
* A service id can contain lowercased letters, digits, underscores, and dots.
* Underscores are used to separate words, and dots to group services
* under namespaces:
*
* <ul>
* <li>request</li>
* <li>mysql_session_storage</li>
* <li>symfony.mysql_session_storage</li>
* </ul>
*
* A service can also be defined by creating a method named
* getXXXService(), where XXX is the camelized version of the id:
*
* <ul>
* <li>request -> getRequestService()</li>
* <li>mysql_session_storage -> getMysqlSessionStorageService()</li>
* <li>symfony.mysql_session_storage -> getSymfony_MysqlSessionStorageService()</li>
* </ul>
* Parameter keys are case insensitive.
*
* The container can have three possible behaviors when a service does not exist:
*
Expand All @@ -70,11 +51,6 @@ class Container implements ResettableContainerInterface
protected $aliases = array();
protected $loading = array();

/**
* @internal
*/
protected $normalizedIds = array();

private $envCache = array();
private $compiled = false;

Expand Down Expand Up @@ -171,8 +147,6 @@ public function setParameter($name, $value)
*/
public function set($id, $service)
{
$id = $this->normalizeId($id);

if ('service_container' === $id) {
throw new InvalidArgumentException('You cannot set service "service_container".');
}
Expand Down Expand Up @@ -212,31 +186,24 @@ public function set($id, $service)
*/
public function has($id)
{
for ($i = 2;;) {
if (isset($this->privates[$id])) {
@trigger_error(sprintf('Checking for the existence of the "%s" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED);
}
if ('service_container' === $id) {
return true;
}
if (isset($this->aliases[$id])) {
$id = $this->aliases[$id];
}
if (isset($this->services[$id])) {
return true;
}

if (isset($this->methodMap[$id])) {
return true;
}

if (--$i && $id !== $normalizedId = $this->normalizeId($id)) {
$id = $normalizedId;
continue;
}
if (isset($this->privates[$id])) {
@trigger_error(sprintf('Checking for the existence of the "%s" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED);
}
if ('service_container' === $id) {
return true;
}
if (isset($this->aliases[$id])) {
$id = $this->aliases[$id];
}
if (isset($this->services[$id])) {
return true;
}

return false;
if (isset($this->methodMap[$id])) {
return true;
}

return false;
}

/**
Expand All @@ -258,69 +225,60 @@ public function has($id)
*/
public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
{
// Attempt to retrieve the service by checking first aliases then
// available services. Service IDs are case insensitive, however since
// this method can be called thousands of times during a request, avoid
// calling $this->normalizeId($id) unless necessary.
for ($i = 2;;) {
if (isset($this->privates[$id])) {
@trigger_error(sprintf('Requesting the "%s" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED);
}
if ('service_container' === $id) {
return $this;
}
if (isset($this->aliases[$id])) {
$id = $this->aliases[$id];
}
if (isset($this->privates[$id])) {
@trigger_error(sprintf('Requesting the "%s" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED);
}
if ('service_container' === $id) {
return $this;
}
if (isset($this->aliases[$id])) {
$id = $this->aliases[$id];
}

// Re-use shared service instance if it exists.
if (isset($this->services[$id])) {
return $this->services[$id];
}
// Re-use shared service instance if it exists.
if (isset($this->services[$id])) {
return $this->services[$id];
}

if (isset($this->loading[$id])) {
throw new ServiceCircularReferenceException($id, array_keys($this->loading));
}
if (isset($this->loading[$id])) {
throw new ServiceCircularReferenceException($id, array_keys($this->loading));
}

if (isset($this->methodMap[$id])) {
$method = $this->methodMap[$id];
} elseif (--$i && $id !== $normalizedId = $this->normalizeId($id)) {
$id = $normalizedId;
continue;
} else {
if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior) {
if (!$id) {
throw new ServiceNotFoundException($id);
}
if (isset($this->methodMap[$id])) {
$method = $this->methodMap[$id];
} else {
if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior) {
if (!$id) {
throw new ServiceNotFoundException($id);
}

$alternatives = array();
foreach ($this->getServiceIds() as $knownId) {
$lev = levenshtein($id, $knownId);
if ($lev <= strlen($id) / 3 || false !== strpos($knownId, $id)) {
$alternatives[] = $knownId;
}
$alternatives = array();
foreach ($this->getServiceIds() as $knownId) {
$lev = levenshtein($id, $knownId);
if ($lev <= strlen($id) / 3 || false !== strpos($knownId, $id)) {
$alternatives[] = $knownId;
}

throw new ServiceNotFoundException($id, null, null, $alternatives);
}

return;
throw new ServiceNotFoundException($id, null, null, $alternatives);
}

$this->loading[$id] = true;
return;
}

try {
$service = $this->$method();
} catch (\Exception $e) {
unset($this->services[$id]);
$this->loading[$id] = true;

throw $e;
} finally {
unset($this->loading[$id]);
}
try {
$service = $this->$method();
} catch (\Exception $e) {
unset($this->services[$id]);

return $service;
throw $e;
} finally {
unset($this->loading[$id]);
}

return $service;
}

/**
Expand All @@ -332,8 +290,6 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE
*/
public function initialized($id)
{
$id = $this->normalizeId($id);

if ('service_container' === $id) {
return false;
}
Expand Down Expand Up @@ -418,32 +374,6 @@ protected function getEnv($name)
return $this->envCache[$name] = $this->getParameter("env($name)");
}

/**
* Returns the case sensitive id used at registration time.
*
* @param string $id
*
* @return string
*
* @internal
*/
public function normalizeId($id)
{
if (!is_string($id)) {
$id = (string) $id;
}
if (isset($this->normalizedIds[$normalizedId = strtolower($id)])) {
$normalizedId = $this->normalizedIds[$normalizedId];
if ($id !== $normalizedId) {
@trigger_error(sprintf('Service identifiers will be made case sensitive in Symfony 4.0. Using "%s" instead of "%s" is deprecated since version 3.3.', $id, $normalizedId), E_USER_DEPRECATED);
}
} else {
$normalizedId = $this->normalizedIds[$normalizedId] = $id;
}

return $normalizedId;
}

private function __clone()
{
}
Expand Down

0 comments on commit a55cbf8

Please sign in to comment.