Last active
August 14, 2021 18:35
-
-
Save jzawadzki/641f67fc0f2ec4c3616add8fbdffb80d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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