[DependencyInjection] Implement psr/container 1.1

This commit is contained in:
Alexander M. Turek 2021-03-05 17:53:08 +01:00
parent 57953845ad
commit d9095aa892
8 changed files with 14 additions and 16 deletions

View File

@ -93,7 +93,7 @@ class TestContainer extends Container
/**
* {@inheritdoc}
*/
public function has($id): bool
public function has(string $id): bool
{
return $this->getPublicContainer()->has($id) || $this->getPrivateContainer()->has($id);
}
@ -101,7 +101,7 @@ class TestContainer extends Container
/**
* {@inheritdoc}
*/
public function get($id, int $invalidBehavior = /* self::EXCEPTION_ON_INVALID_REFERENCE */ 1): ?object
public function get(string $id, int $invalidBehavior = /* self::EXCEPTION_ON_INVALID_REFERENCE */ 1): ?object
{
return $this->getPrivateContainer()->has($id) ? $this->getPrivateContainer()->get($id) : $this->getPublicContainer()->get($id, $invalidBehavior);
}

View File

@ -192,7 +192,7 @@ class Container implements ContainerInterface, ResetInterface
*
* @return bool true if the service is defined, false otherwise
*/
public function has($id)
public function has(string $id)
{
if (isset($this->aliases[$id])) {
$id = $this->aliases[$id];
@ -221,7 +221,7 @@ class Container implements ContainerInterface, ResetInterface
*
* @see Reference
*/
public function get($id, int $invalidBehavior = /* self::EXCEPTION_ON_INVALID_REFERENCE */ 1)
public function get(string $id, int $invalidBehavior = /* self::EXCEPTION_ON_INVALID_REFERENCE */ 1)
{
return $this->services[$id]
?? $this->services[$id = $this->aliases[$id] ?? $id]

View File

@ -517,10 +517,8 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
*
* @return bool true if the service is defined, false otherwise
*/
public function has($id)
public function has(string $id)
{
$id = (string) $id;
return isset($this->definitions[$id]) || isset($this->aliasDefinitions[$id]) || parent::has($id);
}
@ -539,9 +537,9 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
*
* @see Reference
*/
public function get($id, int $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)
public function get(string $id, int $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)
{
if ($this->isCompiled() && isset($this->removedIds[$id = (string) $id]) && ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE >= $invalidBehavior) {
if ($this->isCompiled() && isset($this->removedIds[$id]) && ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE >= $invalidBehavior) {
return parent::get($id);
}

View File

@ -48,7 +48,7 @@ interface ContainerInterface extends PsrContainerInterface
*
* @see Reference
*/
public function get($id, int $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE);
public function get(string $id, int $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE);
/**
* Returns true if the given service is defined.
@ -57,7 +57,7 @@ interface ContainerInterface extends PsrContainerInterface
*
* @return bool true if the service is defined, false otherwise
*/
public function has($id);
public function has(string $id);
/**
* Check for whether or not a service has been initialized.

View File

@ -17,7 +17,7 @@
],
"require": {
"php": ">=7.2.5",
"psr/container": "^1.0",
"psr/container": "^1.1.1",
"symfony/deprecation-contracts": "^2.1",
"symfony/polyfill-php80": "^1.15",
"symfony/service-contracts": "^1.1.6|^2"

View File

@ -43,7 +43,7 @@ trait ServiceLocatorTrait
*
* @return bool
*/
public function has($id)
public function has(string $id)
{
return isset($this->factories[$id]);
}
@ -53,7 +53,7 @@ trait ServiceLocatorTrait
*
* @return mixed
*/
public function get($id)
public function get(string $id)
{
if (!isset($this->factories[$id])) {
throw $this->createNotFoundException($id);

View File

@ -17,7 +17,7 @@
],
"require": {
"php": ">=7.2.5",
"psr/container": "^1.0"
"psr/container": "^1.1"
},
"suggest": {
"symfony/service-implementation": ""

View File

@ -18,7 +18,7 @@
"require": {
"php": ">=7.2.5",
"psr/cache": "^1.0|^2.0|^3.0",
"psr/container": "^1.0",
"psr/container": "^1.1",
"psr/event-dispatcher": "^1.0"
},
"require-dev": {