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 / XmlDescriptor.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
XmlDescriptor.php
207 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\Input\InputArgument;
16 use Matomo\Dependencies\Symfony\Component\Console\Input\InputDefinition;
17 use Matomo\Dependencies\Symfony\Component\Console\Input\InputOption;
18 /**
19 * XML descriptor.
20 *
21 * @author Jean-François Simon <contact@jfsimon.fr>
22 *
23 * @internal
24 */
25 class XmlDescriptor extends Descriptor
26 {
27 public function getInputDefinitionDocument(InputDefinition $definition) : \DOMDocument
28 {
29 $dom = new \DOMDocument('1.0', 'UTF-8');
30 $dom->appendChild($definitionXML = $dom->createElement('definition'));
31 $definitionXML->appendChild($argumentsXML = $dom->createElement('arguments'));
32 foreach ($definition->getArguments() as $argument) {
33 $this->appendDocument($argumentsXML, $this->getInputArgumentDocument($argument));
34 }
35 $definitionXML->appendChild($optionsXML = $dom->createElement('options'));
36 foreach ($definition->getOptions() as $option) {
37 $this->appendDocument($optionsXML, $this->getInputOptionDocument($option));
38 }
39 return $dom;
40 }
41 public function getCommandDocument(Command $command, bool $short = \false) : \DOMDocument
42 {
43 $dom = new \DOMDocument('1.0', 'UTF-8');
44 $dom->appendChild($commandXML = $dom->createElement('command'));
45 $commandXML->setAttribute('id', $command->getName());
46 $commandXML->setAttribute('name', $command->getName());
47 $commandXML->setAttribute('hidden', $command->isHidden() ? 1 : 0);
48 $commandXML->appendChild($usagesXML = $dom->createElement('usages'));
49 $commandXML->appendChild($descriptionXML = $dom->createElement('description'));
50 $descriptionXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $command->getDescription())));
51 if ($short) {
52 foreach ($command->getAliases() as $usage) {
53 $usagesXML->appendChild($dom->createElement('usage', $usage));
54 }
55 } else {
56 $command->mergeApplicationDefinition(\false);
57 foreach (array_merge([$command->getSynopsis()], $command->getAliases(), $command->getUsages()) as $usage) {
58 $usagesXML->appendChild($dom->createElement('usage', $usage));
59 }
60 $commandXML->appendChild($helpXML = $dom->createElement('help'));
61 $helpXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $command->getProcessedHelp())));
62 $definitionXML = $this->getInputDefinitionDocument($command->getDefinition());
63 $this->appendDocument($commandXML, $definitionXML->getElementsByTagName('definition')->item(0));
64 }
65 return $dom;
66 }
67 public function getApplicationDocument(Application $application, ?string $namespace = null, bool $short = \false) : \DOMDocument
68 {
69 $dom = new \DOMDocument('1.0', 'UTF-8');
70 $dom->appendChild($rootXml = $dom->createElement('symfony'));
71 if ('UNKNOWN' !== $application->getName()) {
72 $rootXml->setAttribute('name', $application->getName());
73 if ('UNKNOWN' !== $application->getVersion()) {
74 $rootXml->setAttribute('version', $application->getVersion());
75 }
76 }
77 $rootXml->appendChild($commandsXML = $dom->createElement('commands'));
78 $description = new ApplicationDescription($application, $namespace, \true);
79 if ($namespace) {
80 $commandsXML->setAttribute('namespace', $namespace);
81 }
82 foreach ($description->getCommands() as $command) {
83 $this->appendDocument($commandsXML, $this->getCommandDocument($command, $short));
84 }
85 if (!$namespace) {
86 $rootXml->appendChild($namespacesXML = $dom->createElement('namespaces'));
87 foreach ($description->getNamespaces() as $namespaceDescription) {
88 $namespacesXML->appendChild($namespaceArrayXML = $dom->createElement('namespace'));
89 $namespaceArrayXML->setAttribute('id', $namespaceDescription['id']);
90 foreach ($namespaceDescription['commands'] as $name) {
91 $namespaceArrayXML->appendChild($commandXML = $dom->createElement('command'));
92 $commandXML->appendChild($dom->createTextNode($name));
93 }
94 }
95 }
96 return $dom;
97 }
98 /**
99 * {@inheritdoc}
100 */
101 protected function describeInputArgument(InputArgument $argument, array $options = [])
102 {
103 $this->writeDocument($this->getInputArgumentDocument($argument));
104 }
105 /**
106 * {@inheritdoc}
107 */
108 protected function describeInputOption(InputOption $option, array $options = [])
109 {
110 $this->writeDocument($this->getInputOptionDocument($option));
111 }
112 /**
113 * {@inheritdoc}
114 */
115 protected function describeInputDefinition(InputDefinition $definition, array $options = [])
116 {
117 $this->writeDocument($this->getInputDefinitionDocument($definition));
118 }
119 /**
120 * {@inheritdoc}
121 */
122 protected function describeCommand(Command $command, array $options = [])
123 {
124 $this->writeDocument($this->getCommandDocument($command, $options['short'] ?? \false));
125 }
126 /**
127 * {@inheritdoc}
128 */
129 protected function describeApplication(Application $application, array $options = [])
130 {
131 $this->writeDocument($this->getApplicationDocument($application, $options['namespace'] ?? null, $options['short'] ?? \false));
132 }
133 /**
134 * Appends document children to parent node.
135 */
136 private function appendDocument(\DOMNode $parentNode, \DOMNode $importedParent)
137 {
138 foreach ($importedParent->childNodes as $childNode) {
139 $parentNode->appendChild($parentNode->ownerDocument->importNode($childNode, \true));
140 }
141 }
142 /**
143 * Writes DOM document.
144 */
145 private function writeDocument(\DOMDocument $dom)
146 {
147 $dom->formatOutput = \true;
148 $this->write($dom->saveXML());
149 }
150 private function getInputArgumentDocument(InputArgument $argument) : \DOMDocument
151 {
152 $dom = new \DOMDocument('1.0', 'UTF-8');
153 $dom->appendChild($objectXML = $dom->createElement('argument'));
154 $objectXML->setAttribute('name', $argument->getName());
155 $objectXML->setAttribute('is_required', $argument->isRequired() ? 1 : 0);
156 $objectXML->setAttribute('is_array', $argument->isArray() ? 1 : 0);
157 $objectXML->appendChild($descriptionXML = $dom->createElement('description'));
158 $descriptionXML->appendChild($dom->createTextNode($argument->getDescription()));
159 $objectXML->appendChild($defaultsXML = $dom->createElement('defaults'));
160 $defaults = \is_array($argument->getDefault()) ? $argument->getDefault() : (\is_bool($argument->getDefault()) ? [var_export($argument->getDefault(), \true)] : ($argument->getDefault() ? [$argument->getDefault()] : []));
161 foreach ($defaults as $default) {
162 $defaultsXML->appendChild($defaultXML = $dom->createElement('default'));
163 $defaultXML->appendChild($dom->createTextNode($default));
164 }
165 return $dom;
166 }
167 private function getInputOptionDocument(InputOption $option) : \DOMDocument
168 {
169 $dom = new \DOMDocument('1.0', 'UTF-8');
170 $dom->appendChild($objectXML = $dom->createElement('option'));
171 $objectXML->setAttribute('name', '--' . $option->getName());
172 $pos = strpos($option->getShortcut() ?? '', '|');
173 if (\false !== $pos) {
174 $objectXML->setAttribute('shortcut', '-' . substr($option->getShortcut(), 0, $pos));
175 $objectXML->setAttribute('shortcuts', '-' . str_replace('|', '|-', $option->getShortcut()));
176 } else {
177 $objectXML->setAttribute('shortcut', $option->getShortcut() ? '-' . $option->getShortcut() : '');
178 }
179 $objectXML->setAttribute('accept_value', $option->acceptValue() ? 1 : 0);
180 $objectXML->setAttribute('is_value_required', $option->isValueRequired() ? 1 : 0);
181 $objectXML->setAttribute('is_multiple', $option->isArray() ? 1 : 0);
182 $objectXML->appendChild($descriptionXML = $dom->createElement('description'));
183 $descriptionXML->appendChild($dom->createTextNode($option->getDescription()));
184 if ($option->acceptValue()) {
185 $defaults = \is_array($option->getDefault()) ? $option->getDefault() : (\is_bool($option->getDefault()) ? [var_export($option->getDefault(), \true)] : ($option->getDefault() ? [$option->getDefault()] : []));
186 $objectXML->appendChild($defaultsXML = $dom->createElement('defaults'));
187 if (!empty($defaults)) {
188 foreach ($defaults as $default) {
189 $defaultsXML->appendChild($defaultXML = $dom->createElement('default'));
190 $defaultXML->appendChild($dom->createTextNode($default));
191 }
192 }
193 }
194 if ($option->isNegatable()) {
195 $dom->appendChild($objectXML = $dom->createElement('option'));
196 $objectXML->setAttribute('name', '--no-' . $option->getName());
197 $objectXML->setAttribute('shortcut', '');
198 $objectXML->setAttribute('accept_value', 0);
199 $objectXML->setAttribute('is_value_required', 0);
200 $objectXML->setAttribute('is_multiple', 0);
201 $objectXML->appendChild($descriptionXML = $dom->createElement('description'));
202 $descriptionXML->appendChild($dom->createTextNode('Negate the "--' . $option->getName() . '" option'));
203 }
204 return $dom;
205 }
206 }
207