phpnomad / facade
Requires (Dev)
- phpnomad/di: ^2.0
- phpnomad/logger: ^1.0
- phpnomad/tests: ^0.1.0 || ^0.3.0
This package is auto-updated.
Last update: 2026-04-10 02:09:54 UTC
README
phpnomad/facade provides the base classes and interfaces for building static-bound service facades in PHPNomad. The abstract Facade class resolves its target through the DI container on demand, and the HasFacades interface lets an initializer register its facades with the framework during bootstrap. The pattern is how you end up calling Cache::get($key) or Logger::error($message) from anywhere in your code without wiring up the container at each call site.
Installation
composer require phpnomad/facade
Most applications pull this in as a transitive dependency of phpnomad/core, which ships concrete facades for cache, events, logging, templates, and URL and path resolution.
Overview
PHPNomad\Facade\Abstracts\Facadeis a generic, container-aware base class. A concrete subclass implementsabstractInstance()to name the bound interface, and the base pulls the resolved implementation from the DI container when a facade method is called.PHPNomad\Facade\Interfaces\HasFacadesis the contract initializers implement to advertise their facades. Return an array of facade instances fromgetFacades()and the framework hands each one a container reference during the loader phase.- Resolution is lazy. The container is queried when a facade method fires, not when the facade is registered, so services with expensive dependencies stay cheap until something actually calls them.
- When container resolution throws a
DiException, the base attempts to log a critical error throughLoggerStrategywith the failing abstraction and the container reference before rethrowing, so you get a breadcrumb instead of a bare stack trace.
For working examples of concrete facades built on this base, see the Facades/ directory in phpnomad/core (Cache, Event, Logger, Template, UrlResolver, PathResolver, InstanceProvider).
Documentation
Full framework documentation lives at phpnomad.com.
License
MIT. See LICENSE.txt.