Documentation

ServiceProviderInterface extends ContainerInterface

A ServiceProviderInterface exposes the identifiers and the types of services provided by a container.

Tags
author

Nicolas Grekas p@tchwork.com

author

Mateusz Sip mateusz.sip@gmail.com

Table of Contents

get()  : mixed
Finds an entry of the container by its identifier and returns it.
getProvidedServices()  : array<string|int, string>
Returns an associative array of service types keyed by the identifiers provided by the current container.
has()  : bool
Returns true if the container can return an entry for the given identifier.

Methods

getProvidedServices()

Returns an associative array of service types keyed by the identifiers provided by the current container.

public getProvidedServices() : array<string|int, string>

Examples:

  • ['logger' => 'Psr\Log\LoggerInterface'] means the object provides a service named "logger" that implements Psr\Log\LoggerInterface
  • ['foo' => '?'] means the container provides service name "foo" of unspecified type
  • ['bar' => '?Bar\Baz'] means the container provides a service "bar" of type Bar\Baz|null
Return values
array<string|int, string>

The provided service types, keyed by service names

has()

Returns true if the container can return an entry for the given identifier.

public has(string $id) : bool

Returns false otherwise.

has($id) returning true does not mean that get($id) will not throw an exception. It does however mean that get($id) will not throw a NotFoundExceptionInterface.

Parameters
$id : string

Identifier of the entry to look for.

Return values
bool

Search results