Download the PHP package ghostwriter/container without Composer
On this page you can find all versions of the php package ghostwriter/container. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ghostwriter/container
More information about ghostwriter/container
Files in ghostwriter/container
Package container
Short Description Provides an extensible Dependency Injection Service Container for Automated Object Composition, Interception, and Lifetime Management.
License BSD-3-Clause
Homepage https://github.com/ghostwriter/container
Informations about the package container
Container
Provides an extensible Dependency Injection Service Container for Automated Object Composition, Interception, and Lifetime Management.
It supports autowiring, singleton-style service retrieval, contextual bindings, service factories, post-construction extensions, provider-based registration, and PSR container interoperability.
Why use it?
- Auto-discover providers from Composer metadata
- Autowire concrete classes through reflection
- Cache shared services with
get() - Create fresh instances with
build() - Create services through factories
- Decorate services with extensions
- Override constructor or callable arguments by name or position
- PSR-compatible wrapper
- Register aliases for interfaces and abstractions
- Swap implementations contextually with
bind()
Installation
Install the package with Composer:
Usage
get() resolves a service once and returns the same instance on subsequent calls.
Core concepts
get() vs build()
get(Foo::class)returns the same resolved instance each time.build(Foo::class)creates a new instance every time.
Constructor argument overrides
You can override constructor parameters by name or by position when building a service.
Invoking callables with call()
call() resolves object dependencies for closures, invokable classes, callable arrays, static method strings, and function names.
Checking availability with has()
has() answers whether the container can resolve a service. It does not instantiate the service, run factories, or execute extensions.
Aliases
Use alias() to map an interface or alternative service id to a concrete implementation.
Contextual bindings
Use bind() when one abstraction should resolve differently depending on which concrete class is being built.
Factories
Register a factory when a service needs custom construction logic.
Extensions
Register an extension to mutate or decorate a service after it has been created.
Service providers
Providers group related aliases, factories, extensions, and prebuilt instances.
Provider classes must implement Ghostwriter\Container\Interface\Service\ProviderInterface.
Automatic provider registration from Composer
The container can discover provider classes from Composer package metadata. Add the provider class under extra.ghostwriter.container.provider in your package's composer.json.
When the container is reset or first initialized, it reads Composer metadata, registers discovered providers, and boots them.
PSR container interoperability
The package also provides a PSR-compatible wrapper class: Ghostwriter\Container\PsrContainer.
Testing
Changelog
Please see CHANGELOG.md for more information what has changed recently.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Sponsors
Credits
License
The BSD-3-Clause. Please see License File for more information.