Hoa central
Public Member Functions | Protected Attributes | List of all members
Hoa\Console\Readline\Autocompleter\Word Class Reference
Inheritance diagram for Hoa\Console\Readline\Autocompleter\Word:

Public Member Functions

 __construct (Array $words)
 
 complete (&$prefix)
 
 getWordDefinition ()
 
 setWords (Array $words)
 
 getWords ()
 

Protected Attributes

 $_words = null
 

Detailed Description

Class .

The simplest auto-completer: complete a word.

Definition at line 47 of file Word.php.

Constructor & Destructor Documentation

Hoa\Console\Readline\Autocompleter\Word::__construct ( Array  $words)

Constructor.

Parameters
array$wordsWords.
Returns
void

Definition at line 64 of file Word.php.

65  {
66  $this->setWords($words);
67 
68  return;
69  }

Here is the call graph for this function:

Member Function Documentation

Hoa\Console\Readline\Autocompleter\Word::complete ( $prefix)

Complete a word. Returns null for no word, a full-word or an array of full-words.

Parameters
string&$prefixPrefix to autocomplete.
Returns
mixed

Implements Hoa\Console\Readline\Autocompleter\Autocompleter.

Definition at line 78 of file Word.php.

79  {
80  $out = [];
81  $length = mb_strlen($prefix);
82 
83  foreach ($this->getWords() as $word) {
84  if (mb_substr($word, 0, $length) === $prefix) {
85  $out[] = $word;
86  }
87  }
88 
89  if (empty($out)) {
90  return null;
91  }
92 
93  if (1 === count($out)) {
94  return $out[0];
95  }
96 
97  return $out;
98  }

Here is the call graph for this function:

Hoa\Console\Readline\Autocompleter\Word::getWordDefinition ( )

Get definition of a word.

Returns
string

Implements Hoa\Console\Readline\Autocompleter\Autocompleter.

Definition at line 105 of file Word.php.

106  {
107  return '\b\w+\b';
108  }
Hoa\Console\Readline\Autocompleter\Word::getWords ( )

Get list of words.

Returns
array

Definition at line 129 of file Word.php.

130  {
131  return $this->_words;
132  }

Here is the caller graph for this function:

Hoa\Console\Readline\Autocompleter\Word::setWords ( Array  $words)

Set list of words.

Parameters
array$wordsWords.
Returns
array

Definition at line 116 of file Word.php.

117  {
118  $old = $this->_words;
119  $this->_words = $words;
120 
121  return $old;
122  }

Here is the caller graph for this function:

Member Data Documentation

Hoa\Console\Readline\Autocompleter\Word::$_words = null
protected

Definition at line 54 of file Word.php.


The documentation for this class was generated from the following file: