Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

TextDescriptor.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 7.43 KiB


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   * Text descriptor.
022   *
023   * @author Jean-François Simon <contact@jfsimon.fr>
024   */
025  class TextDescriptor extends Descriptor
026  {
027      /**
028       * {@inheritdoc}
029       */
030      protected function describeInputArgument(InputArgument $argument, array $options = array())
031      {
032          if (null !== $argument->getDefault() && (!is_array($argument->getDefault()) || count($argument->getDefault()))) {
033              $default = sprintf('<comment> (default: %s)</comment>', $this->formatDefaultValue($argument->getDefault()));
034          } else {
035              $default = '';
036          }
037   
038          $nameWidth = isset($options['name_width']) ? $options['name_width'] : strlen($argument->getName());
039          $output = str_replace("\n", "\n".str_repeat(' ', $nameWidth + 2), $argument->getDescription());
040          $output = sprintf(" <info>%-${nameWidth}s</info> %s%s", $argument->getName(), $output, $default);
041   
042          return isset($options['raw_text']) && $options['raw_text'] ? strip_tags($output) : $output;
043      }
044   
045      /**
046       * {@inheritdoc}
047       */
048      protected function describeInputOption(InputOption $option, array $options = array())
049      {
050          if ($option->acceptValue() && null !== $option->getDefault() && (!is_array($option->getDefault()) || count($option->getDefault()))) {
051              $default = sprintf('<comment> (default: %s)</comment>', $this->formatDefaultValue($option->getDefault()));
052          } else {
053              $default = '';
054          }
055   
056          $nameWidth = isset($options['name_width']) ? $options['name_width'] : strlen($option->getName());
057          $nameWithShortcutWidth = $nameWidth - strlen($option->getName()) - 2;
058   
059          $output = sprintf(" <info>%s</info> %-${nameWithShortcutWidth}s%s%s%s",
060              '--'.$option->getName(),
061              $option->getShortcut() ? sprintf('(-%s) ', $option->getShortcut()) : '',
062              str_replace("\n", "\n".str_repeat(' ', $nameWidth + 2), $option->getDescription()),
063              $default,
064              $option->isArray() ? '<comment> (multiple values allowed)</comment>' : ''
065          );
066   
067          return isset($options['raw_text']) && $options['raw_text'] ? strip_tags($output) : $output;
068      }
069   
070      /**
071       * {@inheritdoc}
072       */
073      protected function describeInputDefinition(InputDefinition $definition, array $options = array())
074      {
075          $nameWidth = 0;
076          foreach ($definition->getOptions() as $option) {
077              $nameLength = strlen($option->getName()) + 2;
078              if ($option->getShortcut()) {
079                  $nameLength += strlen($option->getShortcut()) + 3;
080              }
081              $nameWidth = max($nameWidth, $nameLength);
082          }
083          foreach ($definition->getArguments() as $argument) {
084              $nameWidth = max($nameWidth, strlen($argument->getName()));
085          }
086          ++$nameWidth;
087   
088          $messages = array();
089   
090          if ($definition->getArguments()) {
091              $messages[] = '<comment>Arguments:</comment>';
092              foreach ($definition->getArguments() as $argument) {
093                  $messages[] = $this->describeInputArgument($argument, array('name_width' => $nameWidth));
094              }
095              $messages[] = '';
096          }
097   
098          if ($definition->getOptions()) {
099              $messages[] = '<comment>Options:</comment>';
100              foreach ($definition->getOptions() as $option) {
101                  $messages[] = $this->describeInputOption($option, array('name_width' => $nameWidth));
102              }
103              $messages[] = '';
104          }
105   
106          $output = implode("\n", $messages);
107   
108          return isset($options['raw_text']) && $options['raw_text'] ? strip_tags($output) : $output;
109      }
110   
111      /**
112       * {@inheritdoc}
113       */
114      protected function describeCommand(Command $command, array $options = array())
115      {
116          $command->getSynopsis();
117          $command->mergeApplicationDefinition(false);
118          $messages = array('<comment>Usage:</comment>', ' '.$command->getSynopsis(), '');
119   
120          if ($command->getAliases()) {
121              $messages[] = '<comment>Aliases:</comment> <info>'.implode(', ', $command->getAliases()).'</info>';
122          }
123   
124          $messages[] = $this->describeInputDefinition($command->getNativeDefinition());
125   
126          if ($help = $command->getProcessedHelp()) {
127              $messages[] = '<comment>Help:</comment>';
128              $messages[] = ' '.str_replace("\n", "\n ", $help)."\n";
129          }
130   
131          $output = implode("\n", $messages);
132   
133          return isset($options['raw_text']) && $options['raw_text'] ? strip_tags($output) : $output;
134      }
135   
136      /**
137       * {@inheritdoc}
138       */
139      protected function describeApplication(Application $application, array $options = array())
140      {
141          $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
142          $description = new ApplicationDescription($application, $describedNamespace);
143          $messages = array();
144   
145          if (isset($options['raw_text']) && $options['raw_text']) {
146              $width = $this->getColumnWidth($description->getCommands());
147   
148              foreach ($description->getCommands() as $command) {
149                  $messages[] = sprintf("%-${width}s %s", $command->getName(), $command->getDescription());
150              }
151          } else {
152              $width = $this->getColumnWidth($description->getCommands());
153   
154              $messages[] = $application->getHelp();
155              $messages[] = '';
156   
157              if ($describedNamespace) {
158                  $messages[] = sprintf("<comment>Available commands for the \"%s\" namespace:</comment>", $describedNamespace);
159              } else {
160                  $messages[] = '<comment>Available commands:</comment>';
161              }
162   
163              // add commands by namespace
164              foreach ($description->getNamespaces() as $namespace) {
165                  if (!$describedNamespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
166                      $messages[] = '<comment>'.$namespace['id'].'</comment>';
167                  }
168   
169                  foreach ($namespace['commands'] as $name) {
170                      $messages[] = sprintf("  <info>%-${width}s</info> %s", $name, $description->getCommand($name)->getDescription());
171                  }
172              }
173          }
174   
175          $output = implode("\n", $messages);
176   
177          return isset($options['raw_text']) && $options['raw_text'] ? strip_tags($output) : $output;
178      }
179   
180      /**
181       * Formats input option/argument default value.
182       *
183       * @param mixed $default
184       *
185       * @return string
186       */
187      private function formatDefaultValue($default)
188      {
189          if (version_compare(PHP_VERSION, '5.4', '<')) {
190              return str_replace('\/', '/', json_encode($default));
191          }
192   
193          return json_encode($default, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
194      }
195   
196      /**
197       * @param Command[] $commands
198       *
199       * @return int
200       */
201      private function getColumnWidth(array $commands)
202      {
203          $width = 0;
204          foreach ($commands as $command) {
205              $width = strlen($command->getName()) > $width ? strlen($command->getName()) : $width;
206          }
207   
208          return $width + 2;
209      }
210  }
211