PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.12.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.12.1
5.12.1 5.12.0 5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / vendor / prefixed / symfony / console / Descriptor / MarkdownDescriptor.php
matomo / app / vendor / prefixed / symfony / console / Descriptor Last commit date
ApplicationDescription.php 1 year ago Descriptor.php 1 year ago DescriptorInterface.php 2 years ago JsonDescriptor.php 1 year ago MarkdownDescriptor.php 1 year ago TextDescriptor.php 1 year ago XmlDescriptor.php 1 year ago
MarkdownDescriptor.php
156 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 Matomo\Dependencies\Symfony\Component\Console\Descriptor;
12
13 use Matomo\Dependencies\Symfony\Component\Console\Application;
14 use Matomo\Dependencies\Symfony\Component\Console\Command\Command;
15 use Matomo\Dependencies\Symfony\Component\Console\Helper\Helper;
16 use Matomo\Dependencies\Symfony\Component\Console\Input\InputArgument;
17 use Matomo\Dependencies\Symfony\Component\Console\Input\InputDefinition;
18 use Matomo\Dependencies\Symfony\Component\Console\Input\InputOption;
19 use Matomo\Dependencies\Symfony\Component\Console\Output\OutputInterface;
20 /**
21 * Markdown descriptor.
22 *
23 * @author Jean-François Simon <contact@jfsimon.fr>
24 *
25 * @internal
26 */
27 class MarkdownDescriptor extends Descriptor
28 {
29 /**
30 * {@inheritdoc}
31 */
32 public function describe(OutputInterface $output, object $object, array $options = [])
33 {
34 $decorated = $output->isDecorated();
35 $output->setDecorated(\false);
36 parent::describe($output, $object, $options);
37 $output->setDecorated($decorated);
38 }
39 /**
40 * {@inheritdoc}
41 */
42 protected function write(string $content, bool $decorated = \true)
43 {
44 parent::write($content, $decorated);
45 }
46 /**
47 * {@inheritdoc}
48 */
49 protected function describeInputArgument(InputArgument $argument, array $options = [])
50 {
51 $this->write('#### `' . ($argument->getName() ?: '<none>') . "`\n\n" . ($argument->getDescription() ? preg_replace('/\\s*[\\r\\n]\\s*/', "\n", $argument->getDescription()) . "\n\n" : '') . '* Is required: ' . ($argument->isRequired() ? 'yes' : 'no') . "\n" . '* Is array: ' . ($argument->isArray() ? 'yes' : 'no') . "\n" . '* Default: `' . str_replace("\n", '', var_export($argument->getDefault(), \true)) . '`');
52 }
53 /**
54 * {@inheritdoc}
55 */
56 protected function describeInputOption(InputOption $option, array $options = [])
57 {
58 $name = '--' . $option->getName();
59 if ($option->isNegatable()) {
60 $name .= '|--no-' . $option->getName();
61 }
62 if ($option->getShortcut()) {
63 $name .= '|-' . str_replace('|', '|-', $option->getShortcut()) . '';
64 }
65 $this->write('#### `' . $name . '`' . "\n\n" . ($option->getDescription() ? preg_replace('/\\s*[\\r\\n]\\s*/', "\n", $option->getDescription()) . "\n\n" : '') . '* Accept value: ' . ($option->acceptValue() ? 'yes' : 'no') . "\n" . '* Is value required: ' . ($option->isValueRequired() ? 'yes' : 'no') . "\n" . '* Is multiple: ' . ($option->isArray() ? 'yes' : 'no') . "\n" . '* Is negatable: ' . ($option->isNegatable() ? 'yes' : 'no') . "\n" . '* Default: `' . str_replace("\n", '', var_export($option->getDefault(), \true)) . '`');
66 }
67 /**
68 * {@inheritdoc}
69 */
70 protected function describeInputDefinition(InputDefinition $definition, array $options = [])
71 {
72 if ($showArguments = \count($definition->getArguments()) > 0) {
73 $this->write('### Arguments');
74 foreach ($definition->getArguments() as $argument) {
75 $this->write("\n\n");
76 if (null !== ($describeInputArgument = $this->describeInputArgument($argument))) {
77 $this->write($describeInputArgument);
78 }
79 }
80 }
81 if (\count($definition->getOptions()) > 0) {
82 if ($showArguments) {
83 $this->write("\n\n");
84 }
85 $this->write('### Options');
86 foreach ($definition->getOptions() as $option) {
87 $this->write("\n\n");
88 if (null !== ($describeInputOption = $this->describeInputOption($option))) {
89 $this->write($describeInputOption);
90 }
91 }
92 }
93 }
94 /**
95 * {@inheritdoc}
96 */
97 protected function describeCommand(Command $command, array $options = [])
98 {
99 if ($options['short'] ?? \false) {
100 $this->write('`' . $command->getName() . "`\n" . str_repeat('-', Helper::width($command->getName()) + 2) . "\n\n" . ($command->getDescription() ? $command->getDescription() . "\n\n" : '') . '### Usage' . "\n\n" . array_reduce($command->getAliases(), function ($carry, $usage) {
101 return $carry . '* `' . $usage . '`' . "\n";
102 }));
103 return;
104 }
105 $command->mergeApplicationDefinition(\false);
106 $this->write('`' . $command->getName() . "`\n" . str_repeat('-', Helper::width($command->getName()) + 2) . "\n\n" . ($command->getDescription() ? $command->getDescription() . "\n\n" : '') . '### Usage' . "\n\n" . array_reduce(array_merge([$command->getSynopsis()], $command->getAliases(), $command->getUsages()), function ($carry, $usage) {
107 return $carry . '* `' . $usage . '`' . "\n";
108 }));
109 if ($help = $command->getProcessedHelp()) {
110 $this->write("\n");
111 $this->write($help);
112 }
113 $definition = $command->getDefinition();
114 if ($definition->getOptions() || $definition->getArguments()) {
115 $this->write("\n\n");
116 $this->describeInputDefinition($definition);
117 }
118 }
119 /**
120 * {@inheritdoc}
121 */
122 protected function describeApplication(Application $application, array $options = [])
123 {
124 $describedNamespace = $options['namespace'] ?? null;
125 $description = new ApplicationDescription($application, $describedNamespace);
126 $title = $this->getApplicationTitle($application);
127 $this->write($title . "\n" . str_repeat('=', Helper::width($title)));
128 foreach ($description->getNamespaces() as $namespace) {
129 if (ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
130 $this->write("\n\n");
131 $this->write('**' . $namespace['id'] . ':**');
132 }
133 $this->write("\n\n");
134 $this->write(implode("\n", array_map(function ($commandName) use($description) {
135 return sprintf('* [`%s`](#%s)', $commandName, str_replace(':', '', $description->getCommand($commandName)->getName()));
136 }, $namespace['commands'])));
137 }
138 foreach ($description->getCommands() as $command) {
139 $this->write("\n\n");
140 if (null !== ($describeCommand = $this->describeCommand($command, $options))) {
141 $this->write($describeCommand);
142 }
143 }
144 }
145 private function getApplicationTitle(Application $application) : string
146 {
147 if ('UNKNOWN' !== $application->getName()) {
148 if ('UNKNOWN' !== $application->getVersion()) {
149 return sprintf('%s %s', $application->getName(), $application->getVersion());
150 }
151 return $application->getName();
152 }
153 return 'Console Tool';
154 }
155 }
156