KO

TodoJumPhp

davidnurdin 제작 · 데모와 실험
아직 평가가 없어요
▶ 열기 💬 후기 소스 🕘 버전 편집 GitHub
games/todojumphp / src / Command / ListCommand.php · commit 8bfe7cc
<?phpnamespace App\Command;use App\Tasks;use Symfony\Component\Console\Attribute\AsCommand;use Symfony\Component\Console\Command\Command;use Symfony\Component\Console\Helper\Table;use Symfony\Component\Console\Input\InputInterface;use Symfony\Component\Console\Output\OutputInterface;#[AsCommand('list-tasks', 'Lists the tasks', ['ls'])]final class ListCommand extends Command{    public function __construct(private Tasks $tasks)    {        parent::__construct();    }    protected function execute(InputInterface $input, OutputInterface $output): int    {        $rows = [];        foreach ($this->tasks->all() as $i => $task) {            $rows[] = [$i + 1, $task['done'] ? '<info>✔</info>' : ' ', $task['text']];        }        if (!$rows) {            $output->writeln('No task yet: <comment>add "Something to do"</comment>');            return Command::SUCCESS;        }        (new Table($output))->setHeaders(['#', '', 'Task'])->setRows($rows)->render();        return Command::SUCCESS;    }}