Skip to content

Instantly share code, notes, and snippets.

@jzawadzki
Last active August 14, 2021 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jzawadzki/641f67fc0f2ec4c3616add8fbdffb80d to your computer and use it in GitHub Desktop.
Save jzawadzki/641f67fc0f2ec4c3616add8fbdffb80d to your computer and use it in GitHub Desktop.
<?php
declare(strict_types=1);
namespace App\Console;
use Symfony\Bundle\FrameworkBundle\Console\Application as BaseApplication;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Command\ListCommand;
class Application extends BaseApplication
{
private function isCommandVisible(Command $command): bool
{
// we need to leave "list" command as is used for help
if ($command instanceof ListCommand) {
return true;
}
// we only want commands from app namesapce
if (str_starts_with($command->getName(), 'app:')) {
return true;
}
return false;
}
public function add(Command $command)
{
if (!$this->isCommandVisible($command)) {
return null;
}
return parent::add($command);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment