mj-zana / core
Application, service providers, modules and the boot lifecycle for Zana applications
v2.1.0
2026-10-25 20:38 UTC
Requires
- php: ^8.5
- mj-zana/configuration: ^2.0
- mj-zana/container: ^2.0
- psr/log: ^3.0
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-25 20:44:41 UTC
README
Compose an application from service providers and business modules, then boot it. Requires PHP 8.5 or later.
composer require mj-zana/core
Usage
use Zana\Core\Application; $app = Application::configure(basePath: dirname(__DIR__)) ->withProviders(LoggingServiceProvider::class, HttpServiceProvider::class) ->withServices(fn ($services) => $services->singleton(Clock::class)) ->withContainerCache(dirname(__DIR__) . '/var/cache/container.php') // optional ->build(); $app->container()->get(Clock::class); $app->config()->get('app.name'); $app->environment()->isProduction(); $app->terminate();
Modules
Modules are listed explicitly in config/modules.php (ADR-009):
return [ Modules\Patients\PatientsModule::class, Modules\Bmi\BmiModule::class, ];
final class BmiModule extends Module { public function name(): string { return 'Bmi'; } public function dependsOn(): array { return [PatientsModule::class]; } public function register(ServiceCollectionInterface $services): void { $services->scoped(MeasurementRepository::class, PdoMeasurementRepository::class); } public function boot(ContainerInterface $container): void { // add routes, listeners, commands... } }
Modules are sorted so dependencies come first. Unknown dependencies and cycles
fail at startup. Every registration records its origin (module:Bmi), which
appears in container errors and the service graph.
Boot lifecycle
- Load
.env, without overriding real variables. - Detect the environment:
APP_ENV, defaulting to production.APP_DEBUGsets debug. - Build the configuration. Later layers win:
- each module's
Configuration/*.php, under the module's name; config/*.php;config/<environment>/*.php;APP_*environment variables.
- each module's
- Register services, in this order: providers, modules (in dependency order),
then
withServices()callbacks. The environment name is the active container profile. - Build the container (compiled and cached when configured).
- Boot providers and modules, in the same order.
New in 2.1
- Deployment checks. After boot, the application refuses to start
when debug is on for a public
app.url, when debug is on in production, or when a secret is a placeholder in production. Add your own checks with thecore.deployment_checkstag. - Configuration overrides.
withConfiguration(['site.url' => '...'])is the last layer, above environment variables. .env.testing. In thetestingenvironment it replaces.envwhen it exists.
License
MIT — see LICENSE.