-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
deprecate get() for uncompiled container builders #18728
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
UPGRADE FROM 3.1 to 3.2 | ||
======================= | ||
|
||
DependencyInjection | ||
------------------- | ||
|
||
* Calling `get()` on a `ContainerBuilder` instance before compiling the | ||
container is deprecated and will throw an exception in Symfony 4.0. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,6 +94,8 @@ class ContainerBuilder extends Container implements TaggedContainerInterface | |
*/ | ||
private $usedTags = array(); | ||
|
||
private $compiled = false; | ||
|
||
/** | ||
* Sets the track resources flag. | ||
* | ||
|
@@ -409,6 +411,10 @@ public function has($id) | |
*/ | ||
public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE) | ||
{ | ||
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); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may want to think about moving this down after the call to the parent class' There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #19192 |
||
|
||
$id = strtolower($id); | ||
|
||
if ($service = parent::get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE)) { | ||
|
@@ -543,6 +549,7 @@ public function compile() | |
} | ||
|
||
$compiler->compile($this); | ||
$this->compiled = true; | ||
|
||
if ($this->trackResources) { | ||
foreach ($this->definitions as $definition) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wdyt about replacing
and will throw
byand throws
?