debuss-a / awareness
A set of interfaces and traits to make your classes AWARE, just like JCVD.
Installs: 12
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/debuss-a/awareness
Requires
- php: ^8.0
- mezzio/mezzio-template: ^3.0
- psr/cache: ^3.0
- psr/container: ^2.0
- psr/event-dispatcher: ^1.0
- psr/http-client: ^1.0
- psr/http-factory: ^1.1
- psr/simple-cache: ^3.0
This package is auto-updated.
Last update: 2026-01-27 21:18:13 UTC
README
A set of interfaces and traits to make your classes AWARE, just like JCVD.
What is this?
Awareness provides a collection of PSR-compliant "aware" interfaces and traits that allow your classes to declare and receive dependencies through setter injection. Each interface follows the -aware pattern, making it easy to implement dependency injection in a standardized way.
Why use Awareness?
Perfect for Inflectors
Awareness interfaces are particularly useful with dependency injection containers that support inflectors, such as League Container. Inflectors allow you to automatically inject dependencies into any class implementing a specific interface, without having to configure each class individually.
Example with League Container:
use League\Container\Container; use Psr\Http\Client\ClientInterface; use Awareness\ClientAwareInterface; $container = new Container(); // Register your HTTP client $container->add(ClientInterface::class, GuzzleClient::class); // Set up an inflector: any class implementing ClientAwareInterface // will automatically get the HTTP client injected $container->inflector(ClientAwareInterface::class) ->invokeMethod('setClient', [ClientInterface::class]); // Now any ClientAwareInterface implementation gets the client automatically! $myService = $container->get(MyApiService::class); // MyApiService now has the HTTP client injected via setClient()
This approach is extremely powerful because:
- ✅ No per-class configuration needed - just implement the interface and use the trait
- ✅ Consistent dependency injection - same pattern across your entire application
- ✅ Clean separation of concerns - dependencies are clearly declared through interfaces
- ✅ Easy testing - swap implementations by just using different inflector configurations
Simple Implementation
To make a class "aware" of a dependency:
- Implement the corresponding aware interface
- Use the corresponding aware trait (optional, but recommended)
use Awareness\CacheAwareInterface; use Awareness\CacheAwareTrait; class MyService implements CacheAwareInterface { use CacheAwareTrait; public function doSomething() { // Access the cache through $this->cache $this->cache->set('key', 'value'); } }
Available Interfaces & Traits
Awareness covers all major PSR interfaces:
PSR-6: Cache
CacheItemPoolAwareInterface/CacheItemPoolAwareTrait
PSR-11: Container
ContainerAwareInterface/ContainerAwareTrait
PSR-14: Event Dispatcher
EventDispatcherAwareInterface/EventDispatcherAwareTrait
PSR-16: Simple Cache
CacheAwareInterface/CacheAwareTrait
PSR-17: HTTP Factories
RequestFactoryAwareInterface/RequestFactoryAwareTraitResponseFactoryAwareInterface/ResponseFactoryAwareTraitServerRequestFactoryAwareInterface/ServerRequestFactoryAwareTraitStreamFactoryAwareInterface/StreamFactoryAwareTraitUploadedFileFactoryAwareInterface/UploadedFileFactoryAwareTraitUriFactoryAwareInterface/UriFactoryAwareTrait
PSR-18: HTTP Client
ClientAwareInterface/ClientAwareTrait
And other useful interfaces :
Mezzio Template Renderer
TemplateRendererAwareInterface/TemplateRendererAwareTrait
Installation
composer require debuss-a/awareness
Requirements
- PHP 8.0 or higher