本文整理汇总了PHP中Parse::execute方法的典型用法代码示例。如果您正苦于以下问题:PHP Parse::execute方法的具体用法?PHP Parse::execute怎么用?PHP Parse::execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parse
的用法示例。
在下文中一共展示了Parse::execute方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Execute the argument parsing given the input from the command line
* in $_SERVER['argv']
*
* @param array $args Arguments list from the PHP input
* @return array Parsed argument results
*/
public function execute($args, array $config = array())
{
// Strip off the first item, it's the script name
array_shift($args);
$values = [];
// Set any defaults we may have
if (isset($config['default'])) {
foreach ($config['default'] as $key => $value) {
$values[$key] = $value;
}
}
foreach ($args as $argument) {
list($name, $value) = Parse::execute($argument);
// see if we can find a matching option
if ($name !== null) {
$values[$name] = $value;
} else {
$values[] = $value;
}
}
// See if we have ann required params
if (isset($config['required'])) {
$missing = [];
foreach ($config['required'] as $index => $param) {
if (!isset($values[$param])) {
$missing[] = $param;
}
}
if (!empty($missing)) {
throw new Exception\MissingRequiredException('Missing required params: ' . implode(', ', $missing));
}
}
return $values;
}
示例2: execute
/**
* (non-PHPdoc)
* @see \DasRed\Translation\Command\Executor\Log\Parse::execute()
*/
public function execute()
{
$file = $this->getArguments()[1];
if (file_exists($file) === true) {
unlink($file);
}
$this->write('File', 'LineNumber', 'Key', 'Locale', 'Count of Matches');
return parent::execute();
}
示例3: testParseValidArgumentString
/**
* @dataProvider argumentStringProvider
*/
public function testParseValidArgumentString($argument, $result)
{
$parse = new Parse();
$parseResult = $parse->execute($argument);
$this->assertEquals($parseResult, $result);
}