[DependencyInjection] Implement psr/container 1.1
This commit is contained in:
parent
57953845ad
commit
d9095aa892
@ -93,7 +93,7 @@ class TestContainer extends Container
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function has($id): bool
|
public function has(string $id): bool
|
||||||
{
|
{
|
||||||
return $this->getPublicContainer()->has($id) || $this->getPrivateContainer()->has($id);
|
return $this->getPublicContainer()->has($id) || $this->getPrivateContainer()->has($id);
|
||||||
}
|
}
|
||||||
@ -101,7 +101,7 @@ class TestContainer extends Container
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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);
|
return $this->getPrivateContainer()->has($id) ? $this->getPrivateContainer()->get($id) : $this->getPublicContainer()->get($id, $invalidBehavior);
|
||||||
}
|
}
|
||||||
|
@ -192,7 +192,7 @@ class Container implements ContainerInterface, ResetInterface
|
|||||||
*
|
*
|
||||||
* @return bool true if the service is defined, false otherwise
|
* @return bool true if the service is defined, false otherwise
|
||||||
*/
|
*/
|
||||||
public function has($id)
|
public function has(string $id)
|
||||||
{
|
{
|
||||||
if (isset($this->aliases[$id])) {
|
if (isset($this->aliases[$id])) {
|
||||||
$id = $this->aliases[$id];
|
$id = $this->aliases[$id];
|
||||||
@ -221,7 +221,7 @@ class Container implements ContainerInterface, ResetInterface
|
|||||||
*
|
*
|
||||||
* @see Reference
|
* @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]
|
return $this->services[$id]
|
||||||
?? $this->services[$id = $this->aliases[$id] ?? $id]
|
?? $this->services[$id = $this->aliases[$id] ?? $id]
|
||||||
|
@ -517,10 +517,8 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
|||||||
*
|
*
|
||||||
* @return bool true if the service is defined, false otherwise
|
* @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);
|
return isset($this->definitions[$id]) || isset($this->aliasDefinitions[$id]) || parent::has($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -539,9 +537,9 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
|||||||
*
|
*
|
||||||
* @see Reference
|
* @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);
|
return parent::get($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ interface ContainerInterface extends PsrContainerInterface
|
|||||||
*
|
*
|
||||||
* @see Reference
|
* @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.
|
* 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
|
* @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.
|
* Check for whether or not a service has been initialized.
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.2.5",
|
"php": ">=7.2.5",
|
||||||
"psr/container": "^1.0",
|
"psr/container": "^1.1.1",
|
||||||
"symfony/deprecation-contracts": "^2.1",
|
"symfony/deprecation-contracts": "^2.1",
|
||||||
"symfony/polyfill-php80": "^1.15",
|
"symfony/polyfill-php80": "^1.15",
|
||||||
"symfony/service-contracts": "^1.1.6|^2"
|
"symfony/service-contracts": "^1.1.6|^2"
|
||||||
|
@ -43,7 +43,7 @@ trait ServiceLocatorTrait
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function has($id)
|
public function has(string $id)
|
||||||
{
|
{
|
||||||
return isset($this->factories[$id]);
|
return isset($this->factories[$id]);
|
||||||
}
|
}
|
||||||
@ -53,7 +53,7 @@ trait ServiceLocatorTrait
|
|||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function get($id)
|
public function get(string $id)
|
||||||
{
|
{
|
||||||
if (!isset($this->factories[$id])) {
|
if (!isset($this->factories[$id])) {
|
||||||
throw $this->createNotFoundException($id);
|
throw $this->createNotFoundException($id);
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.2.5",
|
"php": ">=7.2.5",
|
||||||
"psr/container": "^1.0"
|
"psr/container": "^1.1"
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
"symfony/service-implementation": ""
|
"symfony/service-implementation": ""
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.2.5",
|
"php": ">=7.2.5",
|
||||||
"psr/cache": "^1.0|^2.0|^3.0",
|
"psr/cache": "^1.0|^2.0|^3.0",
|
||||||
"psr/container": "^1.0",
|
"psr/container": "^1.1",
|
||||||
"psr/event-dispatcher": "^1.0"
|
"psr/event-dispatcher": "^1.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
Reference in New Issue
Block a user