Stecman\Component\Symfony\Console\BashCompletion\CompletionContext::getWords PHP Method

getWords() public method

Get the contents of the command line, exploded into words based on the configured word break characters
public getWords ( ) : array
return array
    public function getWords()
    {
        if ($this->words === null) {
            $this->splitCommand();
        }
        return $this->words;
    }

Usage Example

 public function testWordBreakingWithSmallInputs()
 {
     $context = new CompletionContext();
     // Cursor at the end of a word and not in the following space has no effect
     $context->setCommandLine('cmd a');
     $context->setCharIndex(5);
     $this->assertEquals(array('cmd', 'a'), $context->getWords());
     $this->assertEquals(1, $context->getWordIndex());
     $this->assertEquals('a', $context->getCurrentWord());
     // As above, but in the middle of the command line string
     $context->setCommandLine('cmd a');
     $context->setCharIndex(3);
     $this->assertEquals(array('cmd', 'a'), $context->getWords());
     $this->assertEquals(0, $context->getWordIndex());
     $this->assertEquals('cmd', $context->getCurrentWord());
     // Cursor at the end of the command line with a space appends an empty word
     $context->setCommandLine('cmd   a ');
     $context->setCharIndex(8);
     $this->assertEquals(array('cmd', 'a', ''), $context->getWords());
     $this->assertEquals(2, $context->getWordIndex());
     $this->assertEquals('', $context->getCurrentWord());
     // Cursor in break space before a word appends an empty word in that position
     $context->setCommandLine('cmd a');
     $context->setCharIndex(4);
     $this->assertEquals(array('cmd', '', 'a'), $context->getWords());
     $this->assertEquals(1, $context->getWordIndex());
     $this->assertEquals('', $context->getCurrentWord());
 }
All Usage Examples Of Stecman\Component\Symfony\Console\BashCompletion\CompletionContext::getWords