CLI and modules

Run php m4w from the application root. The first argument selects a command. Commands contributed by packages become available on the next invocation after installation.

CLI arguments

php m4w
Runs the starter’s dependency injection demo. Ordinary words such as hello world are echoed by the demo. An unknown command containing a colon produces an error and exit status 1.
php m4w --help
Lists the installer and commands discovered in installed packages. help and -h select the same output.
php m4w modules:install [module ...]
With no module arguments, opens the interactive picker. With arguments, selects packages directly and invokes Composer in the application root. Composer must be on PATH.

Module selection

The installer accepts 1 or lib-io for mini4work/lib-io, and 2 or http for mini4work/http. Both modules are under development.

Shell
php m4w modules:install lib-io http

On the command line, pass each selection as a separate argument. The interactive prompt also accepts comma-separated selections. At the prompt, Enter, 0 or end-of-input cancels. Duplicate selections collapse to one package. An unknown selection stops the operation before Composer starts.

The installer runs composer require with the selected packages. A Composer failure makes the CLI exit with status 1. Installation adds dependencies. The application remains responsible for generating files, selecting runtime settings and starting a module.

Composer settings

require.php · ^8.3
The template supports PHP 8.x starting at 8.3. Individual modules may require a newer minor release.
require.mini4work/core · ^2.0
Composer selects a compatible 2.x core. The container and kernel API in this guide belong to that release line.
config.platform.php · 8.3.0
Composer uses this PHP version when resolving dependencies, even on a newer interpreter. The local HTTP module requires PHP ^8.4, so the template’s default platform conflicts with that requirement. For an application deployed on PHP 8.4, set its platform to the deployed version before requiring a compatible published module release.

Module command metadata

On discovery, the starter reads the installed package’s composer.json. For example, a package can expose a scaffold for a single configuration file with this fragment.

JSON
{
  "extra": {
    "m4w": {
      "scaffolds": {
        "demo:config": {
          "description": "Create the demo configuration",
          "files": { "config/demo.php": "stubs/config.php.stub" }
        }
      }
    }
  }
}
Command name and description
Use two lowercase segments separated by a colon. Each starts with a letter and may contain letters, digits and hyphens. The required description appears in CLI help. Names must be unique across packages and command types. The installer reserves modules:install.
extra.m4w.scaffolds.*.files
A nonempty map from an application-relative target to a package-relative template source. Scaffolds accept no arguments. If any target exists, the entire scaffold is skipped. If writing fails partway through, files created by that invocation are removed.
extra.m4w.commands.*.class
The container resolves the handler class and invokes it with the remaining CLI arguments and the application root. Implement __invoke(array $arguments, string $projectRoot): int. Return integer zero on success. A different result is reported as a command failure.

HTTP module example

With a compatible HTTP module installed, check php m4w --help for these commands. Run the scaffold once, then start the listener.

Shell
php m4w http:routes
php m4w http:serve

http:routes creates routes/http.php and app/Controllers/ExampleController.php as a group. http:serve loads the routes file and expects it to return a Router. It accepts one optional server configuration path. A relative path is resolved from the application root. Omit it to use the server defaults.

For protocol and TLS settings, see the web server configuration guide.