Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
XmlDescriptor.php
001 <?php
002
003 /*
004 * This file is part of the Symfony package.
005 *
006 * (c) Fabien Potencier <fabien@symfony.com>
007 *
008 * For the full copyright and license information, please view the LICENSE
009 * file that was distributed with this source code.
010 */
011
012 namespace Symfony\Component\Console\Descriptor;
013
014 use Symfony\Component\Console\Application;
015 use Symfony\Component\Console\Command\Command;
016 use Symfony\Component\Console\Input\InputArgument;
017 use Symfony\Component\Console\Input\InputDefinition;
018 use Symfony\Component\Console\Input\InputOption;
019
020 /**
021 * XML descriptor.
022 *
023 * @author Jean-François Simon <contact@jfsimon.fr>
024 *
025 * @internal
026 */
027 class XmlDescriptor extends Descriptor
028 {
029 /**
030 * @param InputDefinition $definition
031 *
032 * @return \DOMDocument
033 */
034 public function getInputDefinitionDocument(InputDefinition $definition)
035 {
036 $dom = new \DOMDocument('1.0', 'UTF-8');
037 $dom->appendChild($definitionXML = $dom->createElement('definition'));
038
039 $definitionXML->appendChild($argumentsXML = $dom->createElement('arguments'));
040 foreach ($definition->getArguments() as $argument) {
041 $this->appendDocument($argumentsXML, $this->getInputArgumentDocument($argument));
042 }
043
044 $definitionXML->appendChild($optionsXML = $dom->createElement('options'));
045 foreach ($definition->getOptions() as $option) {
046 $this->appendDocument($optionsXML, $this->getInputOptionDocument($option));
047 }
048
049 return $dom;
050 }
051
052 /**
053 * @param Command $command
054 *
055 * @return \DOMDocument
056 */
057 public function getCommandDocument(Command $command)
058 {
059 $dom = new \DOMDocument('1.0', 'UTF-8');
060 $dom->appendChild($commandXML = $dom->createElement('command'));
061
062 $command->getSynopsis();
063 $command->mergeApplicationDefinition(false);
064
065 $commandXML->setAttribute('id', $command->getName());
066 $commandXML->setAttribute('name', $command->getName());
067
068 $commandXML->appendChild($usagesXML = $dom->createElement('usages'));
069
070 foreach (array_merge(array($command->getSynopsis()), $command->getAliases(), $command->getUsages()) as $usage) {
071 $usagesXML->appendChild($dom->createElement('usage', $usage));
072 }
073
074 $commandXML->appendChild($descriptionXML = $dom->createElement('description'));
075 $descriptionXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $command->getDescription())));
076
077 $commandXML->appendChild($helpXML = $dom->createElement('help'));
078 $helpXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $command->getProcessedHelp())));
079
080 $definitionXML = $this->getInputDefinitionDocument($command->getNativeDefinition());
081 $this->appendDocument($commandXML, $definitionXML->getElementsByTagName('definition')->item(0));
082
083 return $dom;
084 }
085
086 /**
087 * @param Application $application
088 * @param string|null $namespace
089 *
090 * @return \DOMDocument
091 */
092 public function getApplicationDocument(Application $application, $namespace = null)
093 {
094 $dom = new \DOMDocument('1.0', 'UTF-8');
095 $dom->appendChild($rootXml = $dom->createElement('symfony'));
096
097 if ($application->getName() !== 'UNKNOWN') {
098 $rootXml->setAttribute('name', $application->getName());
099 if ($application->getVersion() !== 'UNKNOWN') {
100 $rootXml->setAttribute('version', $application->getVersion());
101 }
102 }
103
104 $rootXml->appendChild($commandsXML = $dom->createElement('commands'));
105
106 $description = new ApplicationDescription($application, $namespace);
107
108 if ($namespace) {
109 $commandsXML->setAttribute('namespace', $namespace);
110 }
111
112 foreach ($description->getCommands() as $command) {
113 $this->appendDocument($commandsXML, $this->getCommandDocument($command));
114 }
115
116 if (!$namespace) {
117 $rootXml->appendChild($namespacesXML = $dom->createElement('namespaces'));
118
119 foreach ($description->getNamespaces() as $namespaceDescription) {
120 $namespacesXML->appendChild($namespaceArrayXML = $dom->createElement('namespace'));
121 $namespaceArrayXML->setAttribute('id', $namespaceDescription['id']);
122
123 foreach ($namespaceDescription['commands'] as $name) {
124 $namespaceArrayXML->appendChild($commandXML = $dom->createElement('command'));
125 $commandXML->appendChild($dom->createTextNode($name));
126 }
127 }
128 }
129
130 return $dom;
131 }
132
133 /**
134 * {@inheritdoc}
135 */
136 protected function describeInputArgument(InputArgument $argument, array $options = array())
137 {
138 $this->writeDocument($this->getInputArgumentDocument($argument));
139 }
140
141 /**
142 * {@inheritdoc}
143 */
144 protected function describeInputOption(InputOption $option, array $options = array())
145 {
146 $this->writeDocument($this->getInputOptionDocument($option));
147 }
148
149 /**
150 * {@inheritdoc}
151 */
152 protected function describeInputDefinition(InputDefinition $definition, array $options = array())
153 {
154 $this->writeDocument($this->getInputDefinitionDocument($definition));
155 }
156
157 /**
158 * {@inheritdoc}
159 */
160 protected function describeCommand(Command $command, array $options = array())
161 {
162 $this->writeDocument($this->getCommandDocument($command));
163 }
164
165 /**
166 * {@inheritdoc}
167 */
168 protected function describeApplication(Application $application, array $options = array())
169 {
170 $this->writeDocument($this->getApplicationDocument($application, isset($options['namespace']) ? $options['namespace'] : null));
171 }
172
173 /**
174 * Appends document children to parent node.
175 *
176 * @param \DOMNode $parentNode
177 * @param \DOMNode $importedParent
178 */
179 private function appendDocument(\DOMNode $parentNode, \DOMNode $importedParent)
180 {
181 foreach ($importedParent->childNodes as $childNode) {
182 $parentNode->appendChild($parentNode->ownerDocument->importNode($childNode, true));
183 }
184 }
185
186 /**
187 * Writes DOM document.
188 *
189 * @param \DOMDocument $dom
190 *
191 * @return \DOMDocument|string
192 */
193 private function writeDocument(\DOMDocument $dom)
194 {
195 $dom->formatOutput = true;
196 $this->write($dom->saveXML());
197 }
198
199 /**
200 * @param InputArgument $argument
201 *
202 * @return \DOMDocument
203 */
204 private function getInputArgumentDocument(InputArgument $argument)
205 {
206 $dom = new \DOMDocument('1.0', 'UTF-8');
207
208 $dom->appendChild($objectXML = $dom->createElement('argument'));
209 $objectXML->setAttribute('name', $argument->getName());
210 $objectXML->setAttribute('is_required', $argument->isRequired() ? 1 : 0);
211 $objectXML->setAttribute('is_array', $argument->isArray() ? 1 : 0);
212 $objectXML->appendChild($descriptionXML = $dom->createElement('description'));
213 $descriptionXML->appendChild($dom->createTextNode($argument->getDescription()));
214
215 $objectXML->appendChild($defaultsXML = $dom->createElement('defaults'));
216 $defaults = is_array($argument->getDefault()) ? $argument->getDefault() : (is_bool($argument->getDefault()) ? array(var_export($argument->getDefault(), true)) : ($argument->getDefault() ? array($argument->getDefault()) : array()));
217 foreach ($defaults as $default) {
218 $defaultsXML->appendChild($defaultXML = $dom->createElement('default'));
219 $defaultXML->appendChild($dom->createTextNode($default));
220 }
221
222 return $dom;
223 }
224
225 /**
226 * @param InputOption $option
227 *
228 * @return \DOMDocument
229 */
230 private function getInputOptionDocument(InputOption $option)
231 {
232 $dom = new \DOMDocument('1.0', 'UTF-8');
233
234 $dom->appendChild($objectXML = $dom->createElement('option'));
235 $objectXML->setAttribute('name', '--'.$option->getName());
236 $pos = strpos($option->getShortcut(), '|');
237 if (false !== $pos) {
238 $objectXML->setAttribute('shortcut', '-'.substr($option->getShortcut(), 0, $pos));
239 $objectXML->setAttribute('shortcuts', '-'.implode('|-', explode('|', $option->getShortcut())));
240 } else {
241 $objectXML->setAttribute('shortcut', $option->getShortcut() ? '-'.$option->getShortcut() : '');
242 }
243 $objectXML->setAttribute('accept_value', $option->acceptValue() ? 1 : 0);
244 $objectXML->setAttribute('is_value_required', $option->isValueRequired() ? 1 : 0);
245 $objectXML->setAttribute('is_multiple', $option->isArray() ? 1 : 0);
246 $objectXML->appendChild($descriptionXML = $dom->createElement('description'));
247 $descriptionXML->appendChild($dom->createTextNode($option->getDescription()));
248
249 if ($option->acceptValue()) {
250 $defaults = is_array($option->getDefault()) ? $option->getDefault() : (is_bool($option->getDefault()) ? array(var_export($option->getDefault(), true)) : ($option->getDefault() ? array($option->getDefault()) : array()));
251 $objectXML->appendChild($defaultsXML = $dom->createElement('defaults'));
252
253 if (!empty($defaults)) {
254 foreach ($defaults as $default) {
255 $defaultsXML->appendChild($defaultXML = $dom->createElement('default'));
256 $defaultXML->appendChild($dom->createTextNode($default));
257 }
258 }
259 }
260
261 return $dom;
262 }
263 }
264