Download the PHP package blackbonjour/service-manager without Composer
On this page you can find all versions of the php package blackbonjour/service-manager. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download blackbonjour/service-manager
More information about blackbonjour/service-manager
Files in blackbonjour/service-manager
Package service-manager
Short Description Small, lightweight and factory-biased service manager based on the PSR-11 standard.
License MIT
Homepage https://github.com/BlackBonjour/service-manager
Informations about the package service-manager
Service Manager
Small, lightweight and factory-biased service manager based on the PSR-11 standard.
Table of Contents
- Installation
- Basic Usage
- Configuration
- Services
- Factories
- Abstract Factories
- Invokables
- Aliases
- Advanced Usage
- Creating Services with Options
- Using Array Access
- Removing Services
- Abstract Factories
- DynamicFactory
- ReflectionFactory
- API Reference
- ServiceManager
- FactoryInterface
- AbstractFactoryInterface
- InvokableFactory
Installation
You can install the package via composer:
Basic Usage
Configuration
The ServiceManager constructor accepts several configuration arrays:
Services
Services are pre-created instances that are stored in the container:
Factories
Factories are responsible for creating service instances. They can be:
- Classes implementing
FactoryInterface
- Callable objects
- Class strings that resolve to one of the above
Abstract Factories
Abstract factories are used when a service is not explicitly defined. They determine if they can create a requested service:
Invokables
Invokables are classes that can be instantiated directly without a factory:
Aliases
Aliases provide alternative names for services:
Advanced Usage
Creating Services with Options
You can create services with additional options:
Using Array Access
The ServiceManager implements ArrayAccess
, allowing you to use array syntax:
Removing Services
You can remove services from the container:
Abstract Factories
DynamicFactory
The DynamicFactory
looks for a factory class with the same name as the requested service plus "Factory":
ReflectionFactory
The ReflectionFactory
uses PHP's Reflection API to automatically instantiate classes and resolve their dependencies:
API Reference
ServiceManager
The main container class implementing PSR-11's ContainerInterface
.
Methods:
__construct(array $services = [], array $factories = [], array $abstractFactories = [], array $invokables = [], array $aliases = [])
addAbstractFactory(AbstractFactoryInterface|string $abstractFactory): void
addAlias(string $alias, string $id): void
addFactory(string $id, FactoryInterface|callable|string $factory): void
addInvokable(string $id): void
addService(string $id, mixed $service): void
createService(string $id, ?array $options = null): mixed
get(string $id): mixed
has(string $id): bool
removeService(string $id): void
FactoryInterface
Interface for factories that create services.
Methods:
__invoke(ContainerInterface $container, string $service, ?array $options = null)
AbstractFactoryInterface
Interface for abstract factories that can dynamically determine if they can create a service.
Methods:
canCreate(ContainerInterface $container, string $service): bool
__invoke(ContainerInterface $container, string $service, ?array $options = null)
(inherited from FactoryInterface)
InvokableFactory
A factory for creating instances of classes without dependencies.
Methods:
__invoke(ContainerInterface $container, string $service, ?array $options = null)