本文整理汇总了PHP中Cake\Console\ConsoleOptionParser::buildFromArray方法的典型用法代码示例。如果您正苦于以下问题:PHP ConsoleOptionParser::buildFromArray方法的具体用法?PHP ConsoleOptionParser::buildFromArray怎么用?PHP ConsoleOptionParser::buildFromArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Console\ConsoleOptionParser
的用法示例。
在下文中一共展示了ConsoleOptionParser::buildFromArray方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Make a new Subcommand
*
* @param string|array $name The long name of the subcommand, or an array with all the properties.
* @param string $help The help text for this option.
* @param \Cake\Console\ConsoleOptionParser|array|null $parser A parser for this subcommand. Either a ConsoleOptionParser, or an
* array that can be used with ConsoleOptionParser::buildFromArray().
*/
public function __construct($name, $help = '', $parser = null)
{
if (is_array($name) && isset($name['name'])) {
foreach ($name as $key => $value) {
$this->{'_' . $key} = $value;
}
} else {
$this->_name = $name;
$this->_help = $help;
$this->_parser = $parser;
}
if (is_array($this->_parser)) {
$this->_parser['command'] = $this->_name;
$this->_parser = ConsoleOptionParser::buildFromArray($this->_parser);
}
}
示例2: testToArray
/**
* Tests toArray()
*
* @return void
*/
public function testToArray()
{
$spec = ['command' => 'test', 'arguments' => ['name' => ['help' => 'The name'], 'other' => ['help' => 'The other arg']], 'options' => ['name' => ['help' => 'The name'], 'other' => ['help' => 'The other arg']], 'subcommands' => ['initdb' => ['help' => 'make database']], 'description' => 'description text', 'epilog' => 'epilog text'];
$parser = ConsoleOptionParser::buildFromArray($spec);
$result = $parser->toArray();
$this->assertEquals($spec['description'], $result['description']);
$this->assertEquals($spec['epilog'], $result['epilog']);
$options = $result['options'];
$this->assertTrue(isset($options['name']));
$this->assertTrue(isset($options['other']));
$this->assertEquals(2, count($result['arguments']));
$this->assertEquals(1, count($result['subcommands']));
}
示例3: testBuildFromArray
/**
* test building a parser from an array.
*
* @return void
*/
public function testBuildFromArray()
{
$spec = array('command' => 'test', 'arguments' => array('name' => array('help' => 'The name'), 'other' => array('help' => 'The other arg')), 'options' => array('name' => array('help' => 'The name'), 'other' => array('help' => 'The other arg')), 'subcommands' => array('initdb' => array('help' => 'make database')), 'description' => 'description text', 'epilog' => 'epilog text');
$parser = ConsoleOptionParser::buildFromArray($spec);
$this->assertEquals($spec['description'], $parser->description());
$this->assertEquals($spec['epilog'], $parser->epilog());
$options = $parser->options();
$this->assertTrue(isset($options['name']));
$this->assertTrue(isset($options['other']));
$args = $parser->arguments();
$this->assertEquals(2, count($args));
$commands = $parser->subcommands();
$this->assertEquals(1, count($commands));
}