PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.2.0
Independent Analytics – WordPress Analytics Plugin v2.2.0
2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / vendor / symfony / console / Command / CompleteCommand.php
independent-analytics / vendor / symfony / console / Command Last commit date
Command.php 2 years ago CompleteCommand.php 2 years ago DumpCompletionCommand.php 2 years ago HelpCommand.php 2 years ago LazyCommand.php 2 years ago ListCommand.php 2 years ago LockableTrait.php 2 years ago SignalableCommandInterface.php 2 years ago
CompleteCommand.php
150 lines
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11 namespace IAWP_SCOPED\Symfony\Component\Console\Command;
12
13 use IAWP_SCOPED\Symfony\Component\Console\Completion\CompletionInput;
14 use IAWP_SCOPED\Symfony\Component\Console\Completion\CompletionSuggestions;
15 use IAWP_SCOPED\Symfony\Component\Console\Completion\Output\BashCompletionOutput;
16 use IAWP_SCOPED\Symfony\Component\Console\Completion\Output\CompletionOutputInterface;
17 use IAWP_SCOPED\Symfony\Component\Console\Exception\CommandNotFoundException;
18 use IAWP_SCOPED\Symfony\Component\Console\Exception\ExceptionInterface;
19 use IAWP_SCOPED\Symfony\Component\Console\Input\InputInterface;
20 use IAWP_SCOPED\Symfony\Component\Console\Input\InputOption;
21 use IAWP_SCOPED\Symfony\Component\Console\Output\OutputInterface;
22 /**
23 * Responsible for providing the values to the shell completion.
24 *
25 * @author Wouter de Jong <wouter@wouterj.nl>
26 * @internal
27 */
28 final class CompleteCommand extends Command
29 {
30 protected static $defaultName = '|_complete';
31 protected static $defaultDescription = 'Internal command to provide shell completion suggestions';
32 private $completionOutputs;
33 private $isDebug = \false;
34 /**
35 * @param array<string, class-string<CompletionOutputInterface>> $completionOutputs A list of additional completion outputs, with shell name as key and FQCN as value
36 */
37 public function __construct(array $completionOutputs = [])
38 {
39 // must be set before the parent constructor, as the property value is used in configure()
40 $this->completionOutputs = $completionOutputs + ['bash' => BashCompletionOutput::class];
41 parent::__construct();
42 }
43 protected function configure() : void
44 {
45 $this->addOption('shell', 's', InputOption::VALUE_REQUIRED, 'The shell type ("' . \implode('", "', \array_keys($this->completionOutputs)) . '")')->addOption('input', 'i', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'An array of input tokens (e.g. COMP_WORDS or argv)')->addOption('current', 'c', InputOption::VALUE_REQUIRED, 'The index of the "input" array that the cursor is in (e.g. COMP_CWORD)')->addOption('symfony', 'S', InputOption::VALUE_REQUIRED, 'The version of the completion script');
46 }
47 protected function initialize(InputInterface $input, OutputInterface $output)
48 {
49 $this->isDebug = \filter_var(\getenv('SYMFONY_COMPLETION_DEBUG'), \FILTER_VALIDATE_BOOLEAN);
50 }
51 protected function execute(InputInterface $input, OutputInterface $output) : int
52 {
53 try {
54 // uncomment when a bugfix or BC break has been introduced in the shell completion scripts
55 // $version = $input->getOption('symfony');
56 // if ($version && version_compare($version, 'x.y', '>=')) {
57 // $message = sprintf('Completion script version is not supported ("%s" given, ">=x.y" required).', $version);
58 // $this->log($message);
59 // $output->writeln($message.' Install the Symfony completion script again by using the "completion" command.');
60 // return 126;
61 // }
62 $shell = $input->getOption('shell');
63 if (!$shell) {
64 throw new \RuntimeException('The "--shell" option must be set.');
65 }
66 if (!($completionOutput = $this->completionOutputs[$shell] ?? \false)) {
67 throw new \RuntimeException(\sprintf('Shell completion is not supported for your shell: "%s" (supported: "%s").', $shell, \implode('", "', \array_keys($this->completionOutputs))));
68 }
69 $completionInput = $this->createCompletionInput($input);
70 $suggestions = new CompletionSuggestions();
71 $this->log(['', '<comment>' . \date('Y-m-d H:i:s') . '</>', '<info>Input:</> <comment>("|" indicates the cursor position)</>', ' ' . (string) $completionInput, '<info>Command:</>', ' ' . (string) \implode(' ', $_SERVER['argv']), '<info>Messages:</>']);
72 $command = $this->findCommand($completionInput, $output);
73 if (null === $command) {
74 $this->log(' No command found, completing using the Application class.');
75 $this->getApplication()->complete($completionInput, $suggestions);
76 } elseif ($completionInput->mustSuggestArgumentValuesFor('command') && $command->getName() !== $completionInput->getCompletionValue() && !\in_array($completionInput->getCompletionValue(), $command->getAliases(), \true)) {
77 $this->log(' No command found, completing using the Application class.');
78 // expand shortcut names ("cache:cl<TAB>") into their full name ("cache:clear")
79 $suggestions->suggestValues(\array_filter(\array_merge([$command->getName()], $command->getAliases())));
80 } else {
81 $command->mergeApplicationDefinition();
82 $completionInput->bind($command->getDefinition());
83 if (CompletionInput::TYPE_OPTION_NAME === $completionInput->getCompletionType()) {
84 $this->log(' Completing option names for the <comment>' . \get_class($command instanceof LazyCommand ? $command->getCommand() : $command) . '</> command.');
85 $suggestions->suggestOptions($command->getDefinition()->getOptions());
86 } else {
87 $this->log([' Completing using the <comment>' . \get_class($command instanceof LazyCommand ? $command->getCommand() : $command) . '</> class.', ' Completing <comment>' . $completionInput->getCompletionType() . '</> for <comment>' . $completionInput->getCompletionName() . '</>']);
88 if (null !== ($compval = $completionInput->getCompletionValue())) {
89 $this->log(' Current value: <comment>' . $compval . '</>');
90 }
91 $command->complete($completionInput, $suggestions);
92 }
93 }
94 /** @var CompletionOutputInterface $completionOutput */
95 $completionOutput = new $completionOutput();
96 $this->log('<info>Suggestions:</>');
97 if ($options = $suggestions->getOptionSuggestions()) {
98 $this->log(' --' . \implode(' --', \array_map(function ($o) {
99 return $o->getName();
100 }, $options)));
101 } elseif ($values = $suggestions->getValueSuggestions()) {
102 $this->log(' ' . \implode(' ', $values));
103 } else {
104 $this->log(' <comment>No suggestions were provided</>');
105 }
106 $completionOutput->write($suggestions, $output);
107 } catch (\Throwable $e) {
108 $this->log(['<error>Error!</error>', (string) $e]);
109 if ($output->isDebug()) {
110 throw $e;
111 }
112 return 2;
113 }
114 return 0;
115 }
116 private function createCompletionInput(InputInterface $input) : CompletionInput
117 {
118 $currentIndex = $input->getOption('current');
119 if (!$currentIndex || !\ctype_digit($currentIndex)) {
120 throw new \RuntimeException('The "--current" option must be set and it must be an integer.');
121 }
122 $completionInput = CompletionInput::fromTokens($input->getOption('input'), (int) $currentIndex);
123 try {
124 $completionInput->bind($this->getApplication()->getDefinition());
125 } catch (ExceptionInterface $e) {
126 }
127 return $completionInput;
128 }
129 private function findCommand(CompletionInput $completionInput, OutputInterface $output) : ?Command
130 {
131 try {
132 $inputName = $completionInput->getFirstArgument();
133 if (null === $inputName) {
134 return null;
135 }
136 return $this->getApplication()->find($inputName);
137 } catch (CommandNotFoundException $e) {
138 }
139 return null;
140 }
141 private function log($messages) : void
142 {
143 if (!$this->isDebug) {
144 return;
145 }
146 $commandName = \basename($_SERVER['argv'][0]);
147 \file_put_contents(\sys_get_temp_dir() . '/sf_' . $commandName . '.log', \implode(\PHP_EOL, (array) $messages) . \PHP_EOL, \FILE_APPEND);
148 }
149 }
150