示例#1
0
 /**
  * 注册一个helper
  * 
  * @param string $name
  * @param HelperInterface $helper
  */
 function registerHelper($name, HelperInterface $helper)
 {
     $this->console->getHelperRegistry()->register($name, $helper);
 }
示例#2
0
 /**
  * 创建helper对象
  * 
  * @param string $className
  * @return HelperInterface
  */
 protected function create($className)
 {
     return new $className($this->console->getIo());
 }
示例#3
0
文件: slince.php 项目: slince/webapp
<?php

use App\AppKernel;
use Slince\Console\Console;
include __DIR__ . '/../config/bootstrap.php';
$kernel = new AppKernel();
$console = new Console();
$console->addCommands([new \Slince\Application\Command\ClearCommand($kernel)]);
$console->run();
示例#4
0
文件: index.php 项目: slince/console
use Slince\Console\Command;
use Slince\Console\Console;
use Slince\Console\Context\Io;
use Slince\Console\Context\Argv;
use Slince\Console\Context\Option;
use Slince\Console\Question\Question;
use Slince\Console\Question\ConfirmQuestion;
use Slince\Console\Question\ChoiceQuestion;
include __DIR__ . '/../vendor/autoload.php';
class SayHalloCommand extends Command
{
    protected $name = 'hello';
    function configure()
    {
        $this->setDescription('Say hello to someone');
        $this->addArgument('name2', Option::VALUE_REQUIRED);
        $this->addArgument('age', Option::VALUE_OPTIONAL);
        $this->addOption('yell', Option::VALUE_REQUIRED, 'if set will output uppercase');
    }
    function execute(Io $io, Argv $argv)
    {
        $question = new ChoiceQuestion('Whats your favorite sports', ['baskerball', 'foot ball', 'ping pang'], 0);
        $question->setMaxAttempts(3);
        $question->setMultiSelect(true);
        $answer = $this->getHelper('Question')->ask($question);
        $io->write(sprintf("You like %s", implode(', ', $answer)));
    }
}
$console = new Console();
$console->addCommand(new SayHalloCommand());
$console->run();