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 |
MarkdownDescriptor.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\Helper\Helper;
017 use Symfony\Component\Console\Input\InputArgument;
018 use Symfony\Component\Console\Input\InputDefinition;
019 use Symfony\Component\Console\Input\InputOption;
020 use Symfony\Component\Console\Output\OutputInterface;
021
022 /**
023 * Markdown descriptor.
024 *
025 * @author Jean-François Simon <contact@jfsimon.fr>
026 *
027 * @internal
028 */
029 class MarkdownDescriptor extends Descriptor
030 {
031 /**
032 * {@inheritdoc}
033 */
034 public function describe(OutputInterface $output, $object, array $options = [])
035 {
036 $decorated = $output->isDecorated();
037 $output->setDecorated(false);
038
039 parent::describe($output, $object, $options);
040
041 $output->setDecorated($decorated);
042 }
043
044 /**
045 * {@inheritdoc}
046 */
047 protected function write($content, $decorated = true)
048 {
049 parent::write($content, $decorated);
050 }
051
052 /**
053 * {@inheritdoc}
054 */
055 protected function describeInputArgument(InputArgument $argument, array $options = [])
056 {
057 $this->write(
058 '#### `'.($argument->getName() ?: '<none>')."`\n\n"
059 .($argument->getDescription() ? preg_replace('/\s*[\r\n]\s*/', "\n", $argument->getDescription())."\n\n" : '')
060 .'* Is required: '.($argument->isRequired() ? 'yes' : 'no')."\n"
061 .'* Is array: '.($argument->isArray() ? 'yes' : 'no')."\n"
062 .'* Default: `'.str_replace("\n", '', var_export($argument->getDefault(), true)).'`'
063 );
064 }
065
066 /**
067 * {@inheritdoc}
068 */
069 protected function describeInputOption(InputOption $option, array $options = [])
070 {
071 $name = '--'.$option->getName();
072 if ($option->getShortcut()) {
073 $name .= '|-'.str_replace('|', '|-', $option->getShortcut()).'';
074 }
075
076 $this->write(
077 '#### `'.$name.'`'."\n\n"
078 .($option->getDescription() ? preg_replace('/\s*[\r\n]\s*/', "\n", $option->getDescription())."\n\n" : '')
079 .'* Accept value: '.($option->acceptValue() ? 'yes' : 'no')."\n"
080 .'* Is value required: '.($option->isValueRequired() ? 'yes' : 'no')."\n"
081 .'* Is multiple: '.($option->isArray() ? 'yes' : 'no')."\n"
082 .'* Default: `'.str_replace("\n", '', var_export($option->getDefault(), true)).'`'
083 );
084 }
085
086 /**
087 * {@inheritdoc}
088 */
089 protected function describeInputDefinition(InputDefinition $definition, array $options = [])
090 {
091 if ($showArguments = \count($definition->getArguments()) > 0) {
092 $this->write('### Arguments');
093 foreach ($definition->getArguments() as $argument) {
094 $this->write("\n\n");
095 $this->write($this->describeInputArgument($argument));
096 }
097 }
098
099 if (\count($definition->getOptions()) > 0) {
100 if ($showArguments) {
101 $this->write("\n\n");
102 }
103
104 $this->write('### Options');
105 foreach ($definition->getOptions() as $option) {
106 $this->write("\n\n");
107 $this->write($this->describeInputOption($option));
108 }
109 }
110 }
111
112 /**
113 * {@inheritdoc}
114 */
115 protected function describeCommand(Command $command, array $options = [])
116 {
117 $command->getSynopsis();
118 $command->mergeApplicationDefinition(false);
119
120 $this->write(
121 '`'.$command->getName()."`\n"
122 .str_repeat('-', Helper::strlen($command->getName()) + 2)."\n\n"
123 .($command->getDescription() ? $command->getDescription()."\n\n" : '')
124 .'### Usage'."\n\n"
125 .array_reduce(array_merge([$command->getSynopsis()], $command->getAliases(), $command->getUsages()), function ($carry, $usage) {
126 return $carry.'* `'.$usage.'`'."\n";
127 })
128 );
129
130 if ($help = $command->getProcessedHelp()) {
131 $this->write("\n");
132 $this->write($help);
133 }
134
135 if ($command->getNativeDefinition()) {
136 $this->write("\n\n");
137 $this->describeInputDefinition($command->getNativeDefinition());
138 }
139 }
140
141 /**
142 * {@inheritdoc}
143 */
144 protected function describeApplication(Application $application, array $options = [])
145 {
146 $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
147 $description = new ApplicationDescription($application, $describedNamespace);
148 $title = $this->getApplicationTitle($application);
149
150 $this->write($title."\n".str_repeat('=', Helper::strlen($title)));
151
152 foreach ($description->getNamespaces() as $namespace) {
153 if (ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
154 $this->write("\n\n");
155 $this->write('**'.$namespace['id'].':**');
156 }
157
158 $this->write("\n\n");
159 $this->write(implode("\n", array_map(function ($commandName) use ($description) {
160 return sprintf('* [`%s`](#%s)', $commandName, str_replace(':', '', $description->getCommand($commandName)->getName()));
161 }, $namespace['commands'])));
162 }
163
164 foreach ($description->getCommands() as $command) {
165 $this->write("\n\n");
166 $this->write($this->describeCommand($command));
167 }
168 }
169
170 private function getApplicationTitle(Application $application)
171 {
172 if ('UNKNOWN' !== $application->getName()) {
173 if ('UNKNOWN' !== $application->getVersion()) {
174 return sprintf('%s %s', $application->getName(), $application->getVersion());
175 }
176
177 return $application->getName();
178 }
179
180 return 'Console Tool';
181 }
182 }
183