Search by

ziraphp / console

Subu-07

Command-line tooling for ZiraPHP: route and config caching, code generators.

v0.1.0 2026-12-04 07:08 UTC

This package is auto-updated.

Last update: 2026-12-04 07:47:02 UTC


README

Command-line tooling for ZiraPHP, built on Symfony Console.

  • vendor/bin/zira, wired to your application through one bootstrap file.
  • route:list, plus route and configuration caches for production.
  • make:* generators for controllers, commands, service providers and middleware.
  • Your own commands, registered from service providers and built from the container only when they run.
composer require ziraphp/console

Requires PHP 8.2+, ziraphp/framework ^0.1 and symfony/console 7.4+. The cache commands appear when their package is installed: ziraphp/router for route:cache/route:clear, and ziraphp/service-provider for config:cache, config:clear and providers:discover.

Setup

Create bootstrap/app.php returning your application, configured the same way as for web requests:

<?php

use ZiraPHP\Core\Application;
use ZiraPHP\ServiceProvider\Bootstrapper;

require dirname(__DIR__) . '/vendor/autoload.php';

$app = new Application(dirname(__DIR__));

$bootstrapper = new Bootstrapper($app);
$bootstrapper->loadConfig();
$bootstrapper->registerProviders();

return $app;
vendor/bin/zira list
vendor/bin/zira route:list

zira looks for bootstrap/app.php in the working directory; set ZIRA_BOOTSTRAP to use another file. The file may also return a configured ZiraPHP\Console\ConsoleApplication.

Built-in commands

Command Does
route:list [--path=] [--name=] [--json] Shows routes in matching order: methods, path, name, handler, middleware
route:cache [--path=var/cache/routes.php] Writes the registered routes with ZiraPHP\Router\RouteCache
route:clear Deletes the route cache
config:cache [--path=var/cache/config.php] Writes the loaded configuration with ConfigCache
config:clear Deletes the configuration cache
providers:discover [--path=var/cache/providers.php] Rebuilds the provider manifest
make:controller <Name> [--plain] src/Controller/<Name>Controller.php, with route attributes when ziraphp/router is installed
make:command <Name> [--command=app:name] src/Console/<Name>Command.php
make:provider <Name> src/Provider/<Name>ServiceProvider.php
make:middleware <Name> src/Middleware/<Name>Middleware.php (PSR-15)

Relative --path values are inside the application's base path.

Caches in production

route:cache and config:cache write what the application registered while booting. Let bootstrap/app.php register routes and load configuration from source (no cachePath, no RouteCache::remember()), and use the caches only in the web entry point. Otherwise the commands write the old cache back.

A typical deployment:

composer install --no-dev --optimize-autoloader
vendor/bin/zira config:cache
vendor/bin/zira route:cache

To keep the provider manifest current after every Composer change:

"scripts": {
    "post-autoload-dump": "zira providers:discover"
}

Generators

Classes go into the first autoload.psr-4 namespace in your composer.json, for example App\ in src/. Names may include sub-folders (make:controller Admin/Report creates App\Controller\Admin\ReportController). The type suffix is added when missing, and existing files are kept unless you pass --force.

To change a template, copy it from this package's stubs/ folder to stubs/ziraphp/<name>.stub in your project. Placeholders are written as {{ namespace }}, {{ class }} and so on.

Your own commands

Any Symfony command works. Add it to the CommandCollection in a service provider's boot():

use ZiraPHP\Console\CommandCollection;

public function boot(ApplicationInterface $application): void
{
    $application->getContainer()->get(CommandCollection::class)->add(
        SendDigestCommand::class,   // built from the container when it runs
    );
}

Classes with #[AsCommand] are listed from the attribute alone and constructed, with autowired dependencies, only when they run. Classes without it, and command instances, are added immediately.

Development

composer install
composer check   # PHP-CS-Fixer, PHPCS (PSR-12), PHPStan level 9, Psalm level 1, PHPUnit

License

MIT. See LICENSE.