https://github.com/phpnomad/facade
Static-bound method support for building cleaner SDK-style APIs
https://github.com/phpnomad/facade
design-pattern facade framework php phpnomad platform-agnostic sdk
Last synced: 8 days ago
JSON representation
Static-bound method support for building cleaner SDK-style APIs
- Host: GitHub
- URL: https://github.com/phpnomad/facade
- Owner: phpnomad
- License: mit
- Created: 2023-10-13T11:59:13.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2026-04-10T02:09:50.000Z (2 months ago)
- Last Synced: 2026-04-10T04:11:58.235Z (2 months ago)
- Topics: design-pattern, facade, framework, php, phpnomad, platform-agnostic, sdk
- Language: PHP
- Homepage: https://phpnomad.com
- Size: 207 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# phpnomad/facade
[](https://packagist.org/packages/phpnomad/facade)
[](https://packagist.org/packages/phpnomad/facade)
[](https://packagist.org/packages/phpnomad/facade)
[](https://packagist.org/packages/phpnomad/facade)
`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
```bash
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\Facade` is a generic, container-aware base class. A concrete subclass implements `abstractInstance()` 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\HasFacades` is the contract initializers implement to advertise their facades. Return an array of facade instances from `getFacades()` 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 through `LoggerStrategy` with 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](https://phpnomad.com).
## License
MIT. See [LICENSE.txt](LICENSE.txt).