From 60b9ff67cd688e0229df023f6cf50ef4dcf610bb Mon Sep 17 00:00:00 2001 From: Roland Franssen Date: Tue, 16 Aug 2016 21:10:46 +0000 Subject: [PATCH] deprecate ContainerBuilder::set before compilation --- .../DependencyInjection/ContainerBuilder.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index cb3789165891a..89381fd077a75 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -349,6 +349,10 @@ public function getCompiler() */ public function set($id, $service) { + if (!$this->compiled) { + @trigger_error(sprintf('Calling %s() before compiling the container is deprecated since version 3.2 and will throw an exception in 4.0.', __METHOD__), E_USER_DEPRECATED); + } + $id = strtolower($id); if ($this->isFrozen() && (!isset($this->definitions[$id]) || !$this->definitions[$id]->isSynthetic())) { @@ -401,20 +405,20 @@ public function has($id) */ public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE) { + $id = strtolower($id); + + if (!array_key_exists($id, $this->definitions) && isset($this->aliasDefinitions[$id])) { + return $this->get($this->aliasDefinitions[$id]); + } + if (!$this->compiled) { @trigger_error(sprintf('Calling %s() before compiling the container is deprecated since version 3.2 and will throw an exception in 4.0.', __METHOD__), E_USER_DEPRECATED); } - $id = strtolower($id); - if ($service = parent::get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE)) { return $service; } - if (!array_key_exists($id, $this->definitions) && isset($this->aliasDefinitions[$id])) { - return $this->get($this->aliasDefinitions[$id]); - } - try { $definition = $this->getDefinition($id); } catch (ServiceNotFoundException $e) {