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

InputArgument.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 3.21 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\Input;
013   
014  /**
015   * Represents a command line argument.
016   *
017   * @author Fabien Potencier <fabien@symfony.com>
018   *
019   * @api
020   */
021  class InputArgument
022  {
023      const REQUIRED = 1;
024      const OPTIONAL = 2;
025      const IS_ARRAY = 4;
026   
027      private $name;
028      private $mode;
029      private $default;
030      private $description;
031   
032      /**
033       * Constructor.
034       *
035       * @param string  $name        The argument name
036       * @param int     $mode        The argument mode: self::REQUIRED or self::OPTIONAL
037       * @param string  $description A description text
038       * @param mixed   $default     The default value (for self::OPTIONAL mode only)
039       *
040       * @throws \InvalidArgumentException When argument mode is not valid
041       *
042       * @api
043       */
044      public function __construct($name, $mode = null, $description = '', $default = null)
045      {
046          if (null === $mode) {
047              $mode = self::OPTIONAL;
048          } elseif (!is_int($mode) || $mode > 7 || $mode < 1) {
049              throw new \InvalidArgumentException(sprintf('Argument mode "%s" is not valid.', $mode));
050          }
051   
052          $this->name        = $name;
053          $this->mode        = $mode;
054          $this->description = $description;
055   
056          $this->setDefault($default);
057      }
058   
059      /**
060       * Returns the argument name.
061       *
062       * @return string The argument name
063       */
064      public function getName()
065      {
066          return $this->name;
067      }
068   
069      /**
070       * Returns true if the argument is required.
071       *
072       * @return bool    true if parameter mode is self::REQUIRED, false otherwise
073       */
074      public function isRequired()
075      {
076          return self::REQUIRED === (self::REQUIRED & $this->mode);
077      }
078   
079      /**
080       * Returns true if the argument can take multiple values.
081       *
082       * @return bool    true if mode is self::IS_ARRAY, false otherwise
083       */
084      public function isArray()
085      {
086          return self::IS_ARRAY === (self::IS_ARRAY & $this->mode);
087      }
088   
089      /**
090       * Sets the default value.
091       *
092       * @param mixed $default The default value
093       *
094       * @throws \LogicException When incorrect default value is given
095       */
096      public function setDefault($default = null)
097      {
098          if (self::REQUIRED === $this->mode && null !== $default) {
099              throw new \LogicException('Cannot set a default value except for InputArgument::OPTIONAL mode.');
100          }
101   
102          if ($this->isArray()) {
103              if (null === $default) {
104                  $default = array();
105              } elseif (!is_array($default)) {
106                  throw new \LogicException('A default value for an array argument must be an array.');
107              }
108          }
109   
110          $this->default = $default;
111      }
112   
113      /**
114       * Returns the default value.
115       *
116       * @return mixed The default value
117       */
118      public function getDefault()
119      {
120          return $this->default;
121      }
122   
123      /**
124       * Returns the description text.
125       *
126       * @return string The description text
127       */
128      public function getDescription()
129      {
130          return $this->description;
131      }
132  }
133