PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.2.0
Independent Analytics – WordPress Analytics Plugin v2.2.0
2.15.3 2.15.2 2.15.1 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 / Descriptor / XmlDescriptor.php
independent-analytics / vendor / symfony / console / Descriptor Last commit date
ApplicationDescription.php 3 years ago Descriptor.php 3 years ago DescriptorInterface.php 2 years ago JsonDescriptor.php 3 years ago MarkdownDescriptor.php 3 years ago TextDescriptor.php 3 years ago XmlDescriptor.php 3 years 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 IAWP_SCOPED\Symfony\Component\Console\Descriptor;
12
13 use IAWP_SCOPED\Symfony\Component\Console\Application;
14 use IAWP_SCOPED\Symfony\Component\Console\Command\Command;
15 use IAWP_SCOPED\Symfony\Component\Console\Input\InputArgument;
16 use IAWP_SCOPED\Symfony\Component\Console\Input\InputDefinition;
17 use IAWP_SCOPED\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