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

DescriptorHelper.php

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


01  <?php
02   
03  /*
04   * This file is part of the Symfony package.
05   *
06   * (c) Fabien Potencier <fabien@symfony.com>
07   *
08   * For the full copyright and license information, please view the LICENSE
09   * file that was distributed with this source code.
10   */
11   
12  namespace Symfony\Component\Console\Helper;
13   
14  use Symfony\Component\Console\Descriptor\DescriptorInterface;
15  use Symfony\Component\Console\Descriptor\JsonDescriptor;
16  use Symfony\Component\Console\Descriptor\MarkdownDescriptor;
17  use Symfony\Component\Console\Descriptor\TextDescriptor;
18  use Symfony\Component\Console\Descriptor\XmlDescriptor;
19  use Symfony\Component\Console\Output\OutputInterface;
20   
21  /**
22   * This class adds helper method to describe objects in various formats.
23   *
24   * @author Jean-François Simon <contact@jfsimon.fr>
25   */
26  class DescriptorHelper extends Helper
27  {
28      /**
29       * @var DescriptorInterface[]
30       */
31      private $descriptors = array();
32   
33      /**
34       * Constructor.
35       */
36      public function __construct()
37      {
38          $this
39              ->register('txt',  new TextDescriptor())
40              ->register('xml',  new XmlDescriptor())
41              ->register('json', new JsonDescriptor())
42              ->register('md',   new MarkdownDescriptor())
43          ;
44      }
45   
46      /**
47       * Describes an object if supported.
48       *
49       * @param OutputInterface $output
50       * @param object          $object
51       * @param string|null     $format
52       * @param bool            $raw
53       * @param string|null     $namespace
54       *
55       * @throws \InvalidArgumentException when the given format is not supported
56       */
57      public function describe(OutputInterface $output, $object, $format = null, $raw = false, $namespace = null)
58      {
59          $options = array('raw_text' => $raw, 'format' => $format ?: 'txt', 'namespace' => $namespace);
60          $type = !$raw && 'txt' === $options['format'] ? OutputInterface::OUTPUT_NORMAL : OutputInterface::OUTPUT_RAW;
61   
62          if (!isset($this->descriptors[$options['format']])) {
63              throw new \InvalidArgumentException(sprintf('Unsupported format "%s".', $options['format']));
64          }
65   
66          $descriptor = $this->descriptors[$options['format']];
67   
68          $output->writeln($descriptor->describe($object, $options), $type);
69      }
70   
71      /**
72       * Registers a descriptor.
73       *
74       * @param string              $format
75       * @param DescriptorInterface $descriptor
76       *
77       * @return DescriptorHelper
78       */
79      public function register($format, DescriptorInterface $descriptor)
80      {
81          $this->descriptors[$format] = $descriptor;
82   
83          return $this;
84      }
85   
86      /**
87       * {@inheritdoc}
88       */
89      public function getName()
90      {
91          return 'descriptor';
92      }
93  }
94