Oihana PHP System

resolveDependency.php

Table of Contents

Functions

resolveDependency()  : mixed
Resolves a dependency definition from a PSR-11 container or returns a default value.

Functions

resolveDependency()

Resolves a dependency definition from a PSR-11 container or returns a default value.

resolveDependency(string|null $dependency[, ContainerInterface|null $container = null ][, mixed $default = null ]) : mixed

This function attempts to retrieve a service or object from a PSR-11 container if a string identifier is provided. If the container is null, the dependency is not found, or the input is not a string, the provided default value is returned.

Parameters
$dependency : string|null

The container entry ID to resolve.

$container : ContainerInterface|null = null

Optional PSR-11 container to resolve the dependency from.

$default : mixed = null

Value to return if the dependency cannot be resolved.

Tags
throws
ContainerExceptionInterface

If an error occurs while retrieving the dependency from the container.

throws
NotFoundExceptionInterface

If a string definition is provided but not found in the container.

example
$logger = resolveDependency(LoggerInterface::class, $container, new NullLogger());
author

Marc Alcaraz (ekameleon)

since
1.0.0
Return values
mixed

Returns the resolved dependency from the container, or $default if not found.


        
On this page

Search results