-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1146 from oat-sa/fix/LSI-5144/avoid-looping-throu…
…gh-each-service fix: avoid looping through each service when the service ID is missing from the PSR container and has to be loaded via ServiceManager
- Loading branch information
Showing
1 changed file
with
10 additions
and
8 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 |
---|---|---|
|
@@ -15,18 +15,16 @@ | |
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Copyright (c) 2021 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); | ||
* | ||
* @author Gabriel Felipe Soares <[email protected]> | ||
* Copyright (c) 2021-2025 (original work) Open Assessment Technologies SA; | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace oat\generis\model\DependencyInjection; | ||
|
||
use Psr\Container\ContainerInterface; | ||
use Psr\Container\NotFoundExceptionInterface; | ||
use Symfony\Component\DependencyInjection\Container; | ||
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; | ||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | ||
|
||
/** | ||
|
@@ -50,12 +48,16 @@ public function __construct(ParameterBagInterface $parameterBag = null, Containe | |
/** | ||
* @inheritDoc | ||
*/ | ||
public function get($id, int $invalidBehavior = 1) | ||
public function get($id, int $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE) | ||
{ | ||
try { | ||
return parent::get($id, $invalidBehavior); | ||
} catch (ServiceNotFoundException $exception) { | ||
return $this->legacyContainer->get($id); | ||
return parent::get($id, self::NULL_ON_INVALID_REFERENCE) ?? $this->legacyContainer->get($id); | ||
} catch (NotFoundExceptionInterface $exception) { | ||
if ($invalidBehavior >= self::NULL_ON_INVALID_REFERENCE) { | ||
return null; | ||
} | ||
|
||
throw $exception; | ||
} | ||
} | ||
|
||
|