Framework

The mini4work/framework Composer package gives you an application skeleton with a working console entry point. It depends on mini4work/core ^2.0, which creates services, manages their lifetimes and runs your kernel.

Create an application

Install Composer and PHP 8.3 or a later 8.x release. The last argument to create-project names the directory Composer creates.

Shell
composer create-project mini4work/framework myFirstApp
cd myFirstApp
php m4w hello

The starter prints the Mini4Work logo, a message from an injected service and the argument hello. This exercises the container and the console kernel without starting an HTTP listener.

Follow the first run

PHP
use App\Kernels\BaseKernel;
use M4W\Core\Framework;

require __DIR__.'/vendor/autoload.php';

$app = new Framework();
$kernel = $app->make(BaseKernel::class);
$app->run($kernel);
  1. new Framework() creates an isolated container. It binds itself and a default exception handler.
  2. make(BaseKernel::class) injects that container into the kernel constructor. Provider registration begins when the entry point calls run().
  3. BaseServiceProvider registers BaseService as a singleton. When the demo requests it, the container constructs its DependencyService and ConsoleService dependencies.

Extend the application

Put application services in app/Services/. To choose a specific implementation or share an instance, register it in app/ServiceProviders/BaseServiceProvider.php. To change what the application does on startup, edit app/Kernels/BaseKernel.php.