alexeyshockov/plain-commands-bundle
Install the Bundle
Add to composer.json:
"require": {
"alexeyshockov/plain-commands-bundle": "^0.3"
}
Run composer require alexeyshockov/plain-commands-bundle.
Enable the Bundle
Add to config/bundles.php:
Alexeyshockov\PlainCommandsBundle\PlainCommandsBundle::class => ['all' => true],
Register Commands
Tag your command classes in config/services.yaml:
services:
App\Console\Command\:
resource: '../src/Console/Command'
tags: ['plain_commands.set']
Annotate a Command
Create a command class (e.g., src/Console/Command/ExampleCommand.php):
use Alexeyshockov\PlainCommands\Annotation\Command;
class ExampleCommand {
/**
* @Command(name="app:example", description="Runs an example command")
*/
public function run() {
echo "Command executed!";
}
}
Run the Command Execute via CLI:
php bin/console app:example
Define Commands
Use @Command annotations to declare command metadata (name, description, arguments, options).
Example:
/**
* @Command(
* name="app:user:create",
* description="Creates a new user",
* arguments={
* {"name", "name", "User name", "required"},
* {"email", "email", "User email", "required"}
* }
* )
*/
public function createUser(string $name, string $email) {
// Logic here
}
Argument/Option Handling Annotate parameters directly:
/**
* @Command(name="app:filter", arguments={{"limit", "limit", "Max items", "optional", 10}})
*/
public function filter(int $limit = 10) {
// Uses $limit from CLI input
}
Dependency Injection Inject services into commands via constructor or annotations:
use Alexeyshockov\PlainCommands\Annotation\Inject;
class ExampleCommand {
/**
* @Inject
*/
private $logger;
/**
* @Command(name="app:log")
*/
public function log() {
$this->logger->info("Command logged");
}
}
Grouping Commands
Organize commands in namespaces (e.g., App\Console\Command\User) and tag the parent directory in services.yaml.
Integration with Symfony Console
Commands are auto-registered with Symfony’s console component. Use bin/console as usual.
OutputInterface, InputInterface) by extending the base command class if needed.PlainCommandsTestCase (if provided by the underlying library).Annotation Parsing Issues
@Command(name="...") with quotes).// ❌ Fails
@Command name="app:test"
// ✅ Works
/**
* @Command(name="app:test")
*/
Service Tagging
plain_commands.set in services.yaml silenty ignores them.php bin/console debug:container plain_commands.set
Dependency Injection Conflicts
PlainCommandsBundle to skip commands.debug:container to check service availability:
php bin/console debug:container your_service
Symfony Version Mismatch
composer.json or upgrade/downgrade Symfony.Archived Status
Enable Debug Mode
Set APP_DEBUG=1 in .env to see annotation parsing errors in logs.
Check Registered Commands List all registered commands to verify annotations:
php bin/console list
Inspect Annotations Use a tool like phpDocumentor to validate annotation syntax.
Log Annotations Temporarily add logging to the bundle’s compiler pass (if you’re comfortable extending it):
// In a custom compiler pass
$this->container->set('logger', new NullLogger());
Custom Annotation Handlers
Extend the bundle by creating a custom annotation reader or compiler pass to support additional annotations (e.g., @Command\Help).
Post-Processing Commands Use Symfony’s event system to modify commands after registration (e.g., add help text dynamically).
Fork and Maintain Since the package is archived, fork it to add features like:
How can I help you explore Laravel packages today?