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

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

SymfonyQuestionHelper.php

Zuletzt modifiziert: 09.10.2024, 12:56 - Dateigröße: 3.68 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\Helper;
 013   
 014  use Symfony\Component\Console\Exception\LogicException;
 015  use Symfony\Component\Console\Input\InputInterface;
 016  use Symfony\Component\Console\Output\OutputInterface;
 017  use Symfony\Component\Console\Question\ChoiceQuestion;
 018  use Symfony\Component\Console\Question\ConfirmationQuestion;
 019  use Symfony\Component\Console\Question\Question;
 020  use Symfony\Component\Console\Style\SymfonyStyle;
 021  use Symfony\Component\Console\Formatter\OutputFormatter;
 022   
 023  /**
 024   * Symfony Style Guide compliant question helper.
 025   *
 026   * @author Kevin Bond <kevinbond@gmail.com>
 027   */
 028  class SymfonyQuestionHelper extends QuestionHelper
 029  {
 030      /**
 031       * {@inheritdoc}
 032       */
 033      public function ask(InputInterface $input, OutputInterface $output, Question $question)
 034      {
 035          $validator = $question->getValidator();
 036          $question->setValidator(function ($value) use ($validator) {
 037              if (null !== $validator) {
 038                  $value = $validator($value);
 039              } else {
 040                  // make required
 041                  if (!is_array($value) && !is_bool($value) && 0 === strlen($value)) {
 042                      throw new LogicException('A value is required.');
 043                  }
 044              }
 045   
 046              return $value;
 047          });
 048   
 049          return parent::ask($input, $output, $question);
 050      }
 051   
 052      /**
 053       * {@inheritdoc}
 054       */
 055      protected function writePrompt(OutputInterface $output, Question $question)
 056      {
 057          $text = OutputFormatter::escape($question->getQuestion());
 058          $default = $question->getDefault();
 059   
 060          switch (true) {
 061              case null === $default:
 062                  $text = sprintf(' <info>%s</info>:', $text);
 063   
 064                  break;
 065   
 066              case $question instanceof ConfirmationQuestion:
 067                  $text = sprintf(' <info>%s (yes/no)</info> [<comment>%s</comment>]:', $text, $default ? 'yes' : 'no');
 068   
 069                  break;
 070   
 071              case $question instanceof ChoiceQuestion && $question->isMultiselect():
 072                  $choices = $question->getChoices();
 073                  $default = explode(',', $default);
 074   
 075                  foreach ($default as $key => $value) {
 076                      $default[$key] = $choices[trim($value)];
 077                  }
 078   
 079                  $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape(implode(', ', $default)));
 080   
 081                  break;
 082   
 083              case $question instanceof ChoiceQuestion:
 084                  $choices = $question->getChoices();
 085                  $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape($choices[$default]));
 086   
 087                  break;
 088   
 089              default:
 090                  $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape($default));
 091          }
 092   
 093          $output->writeln($text);
 094   
 095          if ($question instanceof ChoiceQuestion) {
 096              $width = max(array_map('strlen', array_keys($question->getChoices())));
 097   
 098              foreach ($question->getChoices() as $key => $value) {
 099                  $output->writeln(sprintf("  [<comment>%-${width}s</comment>] %s", $key, $value));
 100              }
 101          }
 102   
 103          $output->write(' > ');
 104      }
 105   
 106      /**
 107       * {@inheritdoc}
 108       */
 109      protected function writeError(OutputInterface $output, \Exception $error)
 110      {
 111          if ($output instanceof SymfonyStyle) {
 112              $output->newLine();
 113              $output->error($error->getMessage());
 114   
 115              return;
 116          }
 117   
 118          parent::writeError($output, $error);
 119      }
 120  }
 121