Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
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 |
JsonDescriptor.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 * JSON descriptor.
022 *
023 * @author Jean-François Simon <contact@jfsimon.fr>
024 *
025 * @internal
026 */
027 class JsonDescriptor extends Descriptor
028 {
029 /**
030 * {@inheritdoc}
031 */
032 protected function describeInputArgument(InputArgument $argument, array $options = [])
033 {
034 $this->writeData($this->getInputArgumentData($argument), $options);
035 }
036
037 /**
038 * {@inheritdoc}
039 */
040 protected function describeInputOption(InputOption $option, array $options = [])
041 {
042 $this->writeData($this->getInputOptionData($option), $options);
043 }
044
045 /**
046 * {@inheritdoc}
047 */
048 protected function describeInputDefinition(InputDefinition $definition, array $options = [])
049 {
050 $this->writeData($this->getInputDefinitionData($definition), $options);
051 }
052
053 /**
054 * {@inheritdoc}
055 */
056 protected function describeCommand(Command $command, array $options = [])
057 {
058 $this->writeData($this->getCommandData($command), $options);
059 }
060
061 /**
062 * {@inheritdoc}
063 */
064 protected function describeApplication(Application $application, array $options = [])
065 {
066 $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
067 $description = new ApplicationDescription($application, $describedNamespace, true);
068 $commands = [];
069
070 foreach ($description->getCommands() as $command) {
071 $commands[] = $this->getCommandData($command);
072 }
073
074 $data = [];
075 if ('UNKNOWN' !== $application->getName()) {
076 $data['application']['name'] = $application->getName();
077 if ('UNKNOWN' !== $application->getVersion()) {
078 $data['application']['version'] = $application->getVersion();
079 }
080 }
081
082 $data['commands'] = $commands;
083
084 if ($describedNamespace) {
085 $data['namespace'] = $describedNamespace;
086 } else {
087 $data['namespaces'] = array_values($description->getNamespaces());
088 }
089
090 $this->writeData($data, $options);
091 }
092
093 /**
094 * Writes data as json.
095 */
096 private function writeData(array $data, array $options)
097 {
098 $flags = isset($options['json_encoding']) ? $options['json_encoding'] : 0;
099
100 $this->write(json_encode($data, $flags));
101 }
102
103 /**
104 * @return array
105 */
106 private function getInputArgumentData(InputArgument $argument)
107 {
108 return [
109 'name' => $argument->getName(),
110 'is_required' => $argument->isRequired(),
111 'is_array' => $argument->isArray(),
112 'description' => preg_replace('/\s*[\r\n]\s*/', ' ', $argument->getDescription()),
113 'default' => \INF === $argument->getDefault() ? 'INF' : $argument->getDefault(),
114 ];
115 }
116
117 /**
118 * @return array
119 */
120 private function getInputOptionData(InputOption $option)
121 {
122 return [
123 'name' => '--'.$option->getName(),
124 'shortcut' => $option->getShortcut() ? '-'.str_replace('|', '|-', $option->getShortcut()) : '',
125 'accept_value' => $option->acceptValue(),
126 'is_value_required' => $option->isValueRequired(),
127 'is_multiple' => $option->isArray(),
128 'description' => preg_replace('/\s*[\r\n]\s*/', ' ', $option->getDescription()),
129 'default' => \INF === $option->getDefault() ? 'INF' : $option->getDefault(),
130 ];
131 }
132
133 /**
134 * @return array
135 */
136 private function getInputDefinitionData(InputDefinition $definition)
137 {
138 $inputArguments = [];
139 foreach ($definition->getArguments() as $name => $argument) {
140 $inputArguments[$name] = $this->getInputArgumentData($argument);
141 }
142
143 $inputOptions = [];
144 foreach ($definition->getOptions() as $name => $option) {
145 $inputOptions[$name] = $this->getInputOptionData($option);
146 }
147
148 return ['arguments' => $inputArguments, 'options' => $inputOptions];
149 }
150
151 /**
152 * @return array
153 */
154 private function getCommandData(Command $command)
155 {
156 $command->getSynopsis();
157 $command->mergeApplicationDefinition(false);
158
159 return [
160 'name' => $command->getName(),
161 'usage' => array_merge([$command->getSynopsis()], $command->getUsages(), $command->getAliases()),
162 'description' => $command->getDescription(),
163 'help' => $command->getProcessedHelp(),
164 'definition' => $this->getInputDefinitionData($command->getNativeDefinition()),
165 'hidden' => $command->isHidden(),
166 ];
167 }
168 }
169