redant/console

Symfony Console 组件的菜单助手

1.0.5 2023-02-16 18:49 UTC

This package is auto-updated.

Last update: 2024-09-25 11:45:20 UTC


README

菜单选择助手用于 Symfony Console

此菜单助手是 PHPSchool 的 CliMenu 库的桥梁,使其可以轻松地在 Symfony Console 中使用。

它提供了一个交互式菜单,您可以使用箭头键和 Enter 键进行导航。

仅与 UNIX tty 风格终端兼容。

安装

通过 composer require redant/console 安装。

配置

在 HelperSet 中注册助手

use RedAnt\Console\Helper\SelectHelper;

// Further on in your code ...
$this->getHelperSet()->set(new SelectHelper(), 'select');

然后您可以像这样开始使用助手

$helper = $this->getHelper('select');
$value = $helper->select(
    $input,
    'What is your favorite food?',
    [
        'hamburger' => 'Hamburger',
        'pizza'     => 'Pizza',
        'sushi'     => 'Sushi',
        'poke'      => 'Poké bowl'
    ]
);

// $value = 'poke' when the fourth option was chosen
// $value = null when the user canceled

关于

由荷兰乌德勒支的 RedAnt 精心制作。

本项目根据 MIT 许可证的条款授权。