mj-zana / core
Application, service providers, modules and the boot lifecycle for Zana applications
v2.37.0
2026-11-21 13:07 UTC
Requires
- php: ^8.5
- mj-zana/configuration: ^2.0
- mj-zana/container: ^2.4
- psr/log: ^3.0
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-main
- v2.37.0
- v2.36.0
- v2.35.0
- v2.34.0
- v2.33.0
- v2.32.0
- v2.31.0
- v2.30.0
- v2.29.0
- v2.28.0
- v2.27.0
- v2.26.0
- v2.25.0
- v2.24.0
- v2.23.0
- v2.22.0
- v2.21.0
- v2.20.0
- v2.19.0
- v2.18.0
- v2.17.0
- v2.16.0
- v2.15.0
- v2.14.0
- v2.13.0
- v2.12.0
- v2.11.0
- v2.10.0
- v2.9.0
- v2.8.0
- v2.7.0
- v2.6.0
- v2.5.0
- v2.4.0
- v2.3.0
- v2.2.0
- v2.1.0
- v2.0.0
- v2.0.0-rc.1
- v2.0.0-beta.3
- v2.0.0-beta.2
- v2.0.0-beta.1
- v2.0.0-alpha.3
This package is auto-updated.
Last update: 2026-11-24 16:53:45 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 ->withConfigurationCache(dirname(__DIR__) . '/var/cache/config.php') // optional, production only (2.4) ->build(); $app->container()->get(Clock::class); $app->config()->get('app.name'); $app->environment()->isProduction(); $app->terminate();
When .env sets security.secret, both cache files are signed, and a file that was changed is not run (2.35).
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.