lsr / console
Laser framework core - Console helpers
Requires
- php: >=8.4
- nette/di: ^3.2
- symfony/console: ^8|^7
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/extension-installer: ^1.2
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^12
- roave/security-advisories: dev-latest
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
lsr/console connects Symfony Console to Nette DI. It discovers command services, provides a lazy command loader, and adds framework cache-maintenance and container-inspection commands.
Requirements
- PHP
>=8.4. - Nette DI
^3.2and Symfony Console^8|^7. - No PHP extensions are explicitly required by this package's manifest; dependencies may add platform requirements.
- An application-owned DI bootstrap and console entry point. This library does not install a
bin/consoleexecutable.
Installation
composer require lsr/console
Configuration
Register the extension in the application's Nette DI configuration:
extensions: console: Lsr\Console\Di\ConsoleExtension console: name: My application version: '1.0.0' catchExceptions: true
The extension registers Symfony\Component\Console\Application with automatic process exit disabled. catchExceptions defaults to false; choose whether Symfony or the application's outer error handler should handle exceptions. The autowired configuration option selects the Application class when using a subclass.
After the application has compiled and initialized its Nette DI container, its console entry point can run the registered application and propagate its exit code:
use Nette\DI\Container; use Symfony\Component\Console\Application; /** @var Container $container Initialized by the application's bootstrap. */ exit($container->getByType(Application::class)->run());
Application commands
Register Symfony Command subclasses as DI services. For example, this command needs no framework-specific base class:
<?php declare(strict_types=1); namespace App\Console; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand(name: 'app:hello', description: 'Print a greeting.')] final class HelloCommand extends Command { protected function execute(InputInterface $input, OutputInterface $output): int { $output->writeln('Hello!'); return Command::SUCCESS; } }
services: - App\Console\HelloCommand
Discovery is by service type, not by a required tag. Names and descriptions from AsCommand allow lazy loading; duplicate command names or aliases across services cause DI compilation to fail. See ConsoleExtension and CommandLoader.
Built-in commands
container:debug: inspect registered service types and tags; use--parametersto include exported parameters. Values with sensitive-looking parameter names are redacted unless--show-sensitiveis requested. This is name-based filtering, not a guarantee that output is secret-free; review it before sharing.container:clean(aliascontainer:clear): clear compiled container cache files.config:cache:clean(aliasconfig:cache:clear): clear the framework configuration cache.latte:cache:clean(aliaslatte:cache:clear): clear compiled Latte templates.
Cache commands need the application's cache location. Consult each command's --help before deleting cache files, especially when using the package outside LSR Core. Implementations and supported path options are in src/Commands.
Development
CI runs the checks below on PHP 8.4 and 8.5. From a package checkout:
composer install --prefer-dist --no-interaction --no-progress composer cs vendor/bin/phpstan analyse --no-progress vendor/bin/phpunit --no-coverage
composer cs checks coding style without changing files. Run composer cs:fix (or composer cbf) to apply PHP CS Fixer rules from .php-cs-fixer.php.
The suite needs no external services. Install the DOM, mbstring, XML and XMLWriter extensions for PHPUnit. The composer test script enables Xdebug coverage; the CI command explicitly disables coverage collection.
AI coding assistance
See LSR Skills for AI agent skills for working with the LSR framework.
License
Licensed under the MIT License.