chani / safi-core
Core Package for Safi Microframework
v0.1.18
2026-08-02 09:53 UTC
Requires
- php: ^8.5
- psr/container: ^2.0
- psr/log: ^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.64
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^11.0
- rector/rector: ^2.0
- vimeo/psalm: ^6.0
README
Core package for the Safi Microframework (PHP 8.5+). Built around pure constructor injection, explicit composition root wiring, an HTTP context pipeline, attribute routing, and driver contracts.
Architecture Principles
1. Pure Constructor Injection (Assembler)
- No Service Locators: Controllers and services never pull from a global container. All dependencies are explicitly declared in constructors via PHP 8.5 property promotion.
- Composition Root: The
Assembleris used exclusively during application startup (init.inc.phpor CLI entry points) to wire components together deterministically.
2. HTTP Pipeline & Context (Context)
- Combines
Request,Response, andLoggerInterfaceinto a strictContextobject flowing through theMiddlewarePipeline. - Eliminates messy parameter lists and keeps infrastructure concerns out of domain logic.
3. Attribute Routing (#[Route])
- Routes are defined via PHP attributes directly on controller methods.
- Unauthenticated requests are redirected or rejected by authentication middleware configured in the pipeline.
Package Layout
src/
├── Attributes/ # #[Route] definition
├── Cli/ # Command interface & kernel
│ └── Commands/ # Core maintenance tasks
├── Contracts/ # Interfaces (Router, View, Database, Search)
├── Event/ # Synchronous event dispatcher
├── Exception/ # Core exceptions
├── Http/ # Request, Response, Context, Pipeline
├── Services/ # Cache, JobQueue, Security
└── Util/ # Token-based class finder
License
Distributed under the MIT License. Author: Jean Bruenn