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

AbstractOptions.php

Zuletzt modifiziert: 09.10.2024, 12:55 - Dateigröße: 4.61 KiB


 001  <?php
 002  /**
 003   * Zend Framework (http://framework.zend.com/)
 004   *
 005   * @link      http://github.com/zendframework/zf2 for the canonical source repository
 006   * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
 007   * @license   http://framework.zend.com/license/new-bsd New BSD License
 008   */
 009   
 010  namespace Zend\Stdlib;
 011   
 012  use Traversable;
 013   
 014  abstract class AbstractOptions implements ParameterObjectInterface
 015  {
 016      /**
 017       * We use the __ prefix to avoid collisions with properties in
 018       * user-implementations.
 019       *
 020       * @var bool
 021       */
 022      protected $__strictMode__ = true;
 023   
 024      /**
 025       * Constructor
 026       *
 027       * @param  array|Traversable|null $options
 028       */
 029      public function __construct($options = null)
 030      {
 031          if (null !== $options) {
 032              $this->setFromArray($options);
 033          }
 034      }
 035   
 036      /**
 037       * Set one or more configuration properties
 038       *
 039       * @param  array|Traversable|AbstractOptions $options
 040       * @throws Exception\InvalidArgumentException
 041       * @return AbstractOptions Provides fluent interface
 042       */
 043      public function setFromArray($options)
 044      {
 045          if ($options instanceof self) {
 046              $options = $options->toArray();
 047          }
 048   
 049          if (!is_array($options) && !$options instanceof Traversable) {
 050              throw new Exception\InvalidArgumentException(
 051                  sprintf(
 052                      'Parameter provided to %s must be an %s, %s or %s',
 053                      __METHOD__,
 054                      'array',
 055                      'Traversable',
 056                      'Zend\Stdlib\AbstractOptions'
 057                  )
 058              );
 059          }
 060   
 061          foreach ($options as $key => $value) {
 062              $this->__set($key, $value);
 063          }
 064   
 065          return $this;
 066      }
 067   
 068      /**
 069       * Cast to array
 070       *
 071       * @return array
 072       */
 073      public function toArray()
 074      {
 075          $array = array();
 076          $transform = function ($letters) {
 077              $letter = array_shift($letters);
 078              return '_' . strtolower($letter);
 079          };
 080          foreach ($this as $key => $value) {
 081              if ($key === '__strictMode__') {
 082                  continue;
 083              }
 084              $normalizedKey = preg_replace_callback('/([A-Z])/', $transform, $key);
 085              $array[$normalizedKey] = $value;
 086          }
 087          return $array;
 088      }
 089   
 090      /**
 091       * Set a configuration property
 092       *
 093       * @see ParameterObject::__set()
 094       * @param string $key
 095       * @param mixed $value
 096       * @throws Exception\BadMethodCallException
 097       * @return void
 098       */
 099      public function __set($key, $value)
 100      {
 101          $setter = 'set' . str_replace('_', '', $key);
 102   
 103          if (is_callable(array($this, $setter))) {
 104              $this->{$setter}($value);
 105   
 106              return;
 107          }
 108   
 109          if ($this->__strictMode__) {
 110              throw new Exception\BadMethodCallException(sprintf(
 111                  'The option "%s" does not have a callable "%s" ("%s") setter method which must be defined',
 112                  $key,
 113                  'set' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key))),
 114                  $setter
 115              ));
 116          }
 117      }
 118   
 119      /**
 120       * Get a configuration property
 121       *
 122       * @see ParameterObject::__get()
 123       * @param string $key
 124       * @throws Exception\BadMethodCallException
 125       * @return mixed
 126       */
 127      public function __get($key)
 128      {
 129          $getter = 'get' . str_replace('_', '', $key);
 130   
 131          if (is_callable(array($this, $getter))) {
 132              return $this->{$getter}();
 133          }
 134   
 135          throw new Exception\BadMethodCallException(sprintf(
 136              'The option "%s" does not have a callable "%s" getter method which must be defined',
 137              $key,
 138              'get' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key)))
 139          ));
 140      }
 141   
 142      /**
 143       * Test if a configuration property is null
 144       * @see ParameterObject::__isset()
 145       * @param string $key
 146       * @return bool
 147       */
 148      public function __isset($key)
 149      {
 150          $getter = 'get' . str_replace('_', '', $key);
 151   
 152          return method_exists($this, $getter) && null !== $this->__get($key);
 153      }
 154   
 155      /**
 156       * Set a configuration property to NULL
 157       *
 158       * @see ParameterObject::__unset()
 159       * @param string $key
 160       * @throws Exception\InvalidArgumentException
 161       * @return void
 162       */
 163      public function __unset($key)
 164      {
 165          try {
 166              $this->__set($key, null);
 167          } catch (Exception\BadMethodCallException $e) {
 168              throw new Exception\InvalidArgumentException(
 169                  'The class property $' . $key . ' cannot be unset as'
 170                  . ' NULL is an invalid value for it',
 171                  0,
 172                  $e
 173              );
 174          }
 175      }
 176  }
 177