yuralukashik/short-commands-bundle

Short commands for Symfony Console

1.2.1 2022-08-12 14:48 UTC

This package is auto-updated.

Last update: 2024-03-29 22:14:40 UTC


README

  • Install ShortCommandsBundle.
composer require yuralukashik/short-commands-bundle
  • Register a folder with your commands, see config.yml:
short_commands:
  directories:
    - "%kernel.root_dir%/../examples"
  • Create a PHP file, for example examples/example:use-filesystem-service.php. Name of the file example:use-filesystem-service is going to be the name of the command.
  • Return a function from that file with all dependencies as arguments:
<?php

use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Console\Output\OutputInterface;

return function (
    Filesystem $filesystem,
    OutputInterface $output,
    string $name = 'Unknown'
) {
    $currentFileExists = $filesystem->exists(__FILE__);
    $message = $currentFileExists
        ? 'current file really exists'
        : 'current file does not exist';
    $output->writeln("Hey {$name}!");
    $output->writeln("I've just checked and {$message}");
};

Check out /examples for more examples.