-
-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Suggestion class for more advanced completion suggestion
- Loading branch information
Showing
4 changed files
with
51 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,33 +18,37 @@ | |
* | ||
* @author Wouter de Jong <[email protected]> | ||
*/ | ||
class CompletionSuggestions | ||
final class CompletionSuggestions | ||
{ | ||
private $valueSuggestions = []; | ||
private $optionSuggestions = []; | ||
|
||
/** | ||
* Add a suggested value for an input option or argument. | ||
* | ||
* @param string|Suggestion $value | ||
* | ||
* @return $this | ||
*/ | ||
public function suggestValue(string $value): self | ||
public function suggestValue($value): self | ||
{ | ||
$this->valueSuggestions[] = $value; | ||
$this->valueSuggestions[] = !$value instanceof Suggestion ? new Suggestion($value) : $value; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Add multiple suggested values at once for an input option or argument. | ||
* | ||
* @param string[] $values | ||
* @param list<string|Suggestion> $values | ||
* | ||
* @return $this | ||
*/ | ||
public function suggestValues(array $values): self | ||
{ | ||
$this->valueSuggestions = array_merge($this->valueSuggestions, $values); | ||
foreach ($values as $value) { | ||
$this->suggestValue($value); | ||
} | ||
|
||
return $this; | ||
} | ||
|
@@ -86,7 +90,7 @@ public function getOptionSuggestions(): array | |
} | ||
|
||
/** | ||
* @return string[] | ||
* @return Suggestion[] | ||
*/ | ||
public function getValueSuggestions(): array | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Console\Completion; | ||
|
||
/** | ||
* Represents a single suggested value. | ||
* | ||
* @author Wouter de Jong <[email protected]> | ||
*/ | ||
class Suggestion | ||
{ | ||
private $value; | ||
|
||
public function __construct(string $value) | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
public function getValue(): string | ||
{ | ||
return $this->value; | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return $this->getValue(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters