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

ExplodeStrategy.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 3.01 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\Hydrator\Strategy;
 011   
 012  final class ExplodeStrategy implements StrategyInterface
 013  {
 014      /**
 015       * @var string
 016       */
 017      private $valueDelimiter;
 018   
 019      /**
 020       * @var int|null
 021       */
 022      private $explodeLimit;
 023   
 024      /**
 025       * Constructor
 026       *
 027       * @param string   $delimiter    String that the values will be split upon
 028       * @param int|null $explodeLimit Explode limit
 029       */
 030      public function __construct($delimiter = ',', $explodeLimit = null)
 031      {
 032          $this->setValueDelimiter($delimiter);
 033   
 034          $this->explodeLimit = ($explodeLimit === null) ? null : (int) $explodeLimit;
 035      }
 036   
 037      /**
 038       * Sets the delimiter string that the values will be split upon
 039       *
 040       * @param  string $delimiter
 041       * @return self
 042       */
 043      private function setValueDelimiter($delimiter)
 044      {
 045          if (!is_string($delimiter)) {
 046              throw new Exception\InvalidArgumentException(sprintf(
 047                  '%s expects Delimiter to be string, %s provided instead',
 048                  __METHOD__,
 049                  is_object($delimiter) ? get_class($delimiter) : gettype($delimiter)
 050              ));
 051          }
 052   
 053          if (empty($delimiter)) {
 054              throw new Exception\InvalidArgumentException('Delimiter cannot be empty.');
 055          }
 056   
 057          $this->valueDelimiter = $delimiter;
 058      }
 059   
 060      /**
 061       * {@inheritDoc}
 062       *
 063       * Split a string by delimiter
 064       *
 065       * @param string|null $value
 066       *
 067       * @return string[]
 068       *
 069       * @throws Exception\InvalidArgumentException
 070       */
 071      public function hydrate($value)
 072      {
 073          if (null === $value) {
 074              return array();
 075          }
 076   
 077          if (!(is_string($value) || is_numeric($value))) {
 078              throw new Exception\InvalidArgumentException(sprintf(
 079                  '%s expects argument 1 to be string, %s provided instead',
 080                  __METHOD__,
 081                  is_object($value) ? get_class($value) : gettype($value)
 082              ));
 083          }
 084   
 085          if ($this->explodeLimit !== null) {
 086              return explode($this->valueDelimiter, $value, $this->explodeLimit);
 087          }
 088   
 089          return explode($this->valueDelimiter, $value);
 090      }
 091   
 092      /**
 093       * {@inheritDoc}
 094       *
 095       * Join array elements with delimiter
 096       *
 097       * @param string[] $value The original value.
 098       *
 099       * @return string|null
 100       */
 101      public function extract($value)
 102      {
 103          if (!is_array($value)) {
 104              throw new Exception\InvalidArgumentException(sprintf(
 105                  '%s expects argument 1 to be array, %s provided instead',
 106                  __METHOD__,
 107                  is_object($value) ? get_class($value) : gettype($value)
 108              ));
 109          }
 110   
 111          return empty($value) ? null : implode($this->valueDelimiter, $value);
 112      }
 113  }
 114