-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DependencyInjection] added a way to automatically update scoped serv…
…ices A service can now be marked as synchronized; when set, all method calls involving this service will be called each time this service is set. When in a scope, methods are also called to restore the previous version of the service.
- Loading branch information
Showing
22 changed files
with
366 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -206,6 +206,10 @@ public function set($id, $service, $scope = self::SCOPE_CONTAINER) | |
} | ||
|
||
$this->services[$id] = $service; | ||
|
||
if (method_exists($this, $method = 'synchronize'.strtr($id, array('_' => '', '.' => '_')).'Service')) { | ||
$this->$method(); | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -221,7 +225,7 @@ public function has($id) | |
{ | ||
$id = strtolower($id); | ||
|
||
return isset($this->services[$id]) || method_exists($this, 'get'.strtr($id, array('_' => '', '.' => '_')).'Service'); | ||
return array_key_exists($id, $this->services) || method_exists($this, 'get'.strtr($id, array('_' => '', '.' => '_')).'Service'); | ||
} | ||
|
||
/** | ||
|
@@ -247,7 +251,7 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE | |
{ | ||
$id = strtolower($id); | ||
|
||
if (isset($this->services[$id])) { | ||
if (array_key_exists($id, $this->services)) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
stof
Member
|
||
return $this->services[$id]; | ||
} | ||
|
||
|
@@ -263,7 +267,7 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE | |
} catch (\Exception $e) { | ||
unset($this->loading[$id]); | ||
|
||
if (isset($this->services[$id])) { | ||
if (array_key_exists($id, $this->services)) { | ||
unset($this->services[$id]); | ||
} | ||
|
||
|
@@ -289,7 +293,7 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE | |
*/ | ||
public function initialized($id) | ||
{ | ||
return isset($this->services[strtolower($id)]); | ||
return array_key_exists(strtolower($id), $this->services); | ||
} | ||
|
||
/** | ||
|
@@ -393,8 +397,11 @@ public function leaveScope($name) | |
$services = $this->scopeStacks[$name]->pop(); | ||
$this->scopedServices += $services; | ||
|
||
array_unshift($services, $this->services); | ||
$this->services = call_user_func_array('array_merge', $services); | ||
foreach ($services as $array) { | ||
foreach ($array as $id => $service) { | ||
$this->set($id, $service, $name); | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
@fabpot This broke the implementation of
Doctrine\Common\Persistence\AbstractManagerRegistry::resetService
inSymfony\Bridge\Doctrine\Registry
.This class is setting the service to
null
, relying on the fact that it was triggering the instantiation of a new entity manager in Symfony 2.2 and below when callingget
again later. Now, callinggetManager
after resetting the manager in the registry is returningnull
, which breaks the code (as the method should never return null) and thus makes the resetting unusable.With the new logic, I don't see any way to fix the registry implementation, and this is clearly an undocumented BC break in 2.3.