PHP code example of asika / symfony-console-completion
1. Go to this page and download the library: Download asika/symfony-console-completion library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
asika / symfony-console-completion example snippets
protected function getDefaultCommands()
{
//...
$commands[] = new \Stecman\Component\Symfony\Console\BashCompletion\CompletionCommand();
//...
}
class MyCommand extends Command implements CompletionAwareInterface
{
...
public function completeOptionValues($optionName, CompletionContext $context)
{
if ($optionName == 'some-option') {
return ['myvalue', 'other-value', 'word'];
}
}
public function completeArgumentValues($argumentName, CompletionContext $context)
{
if ($argumentName == 'package') {
return $this->getPackageNamesFromDatabase($context->getCurrentWord());
}
}
}
class MyCompletionCommand extends CompletionCommand
{
protected function configureCompletion(CompletionHandler $handler)
{
$handler->addHandlers([
// Instances of Completion go here.
// See below for examples.
]);
}
}
$handler->addHandler(
new Completion(
'walk', // match command name
'direction', // match argument/option name
Completion::TYPE_ARGUMENT, // match definition type (option/argument)
[ // array or callback for results
'north',
'east',
'south',
'west'
]
)
);