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

DateTimeFormatterStrategy.php

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


 01  <?php
 02  /**
 03   * Zend Framework (http://framework.zend.com/)
 04   *
 05   * @link      http://github.com/zendframework/zf2 for the canonical source repository
 06   * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
 07   * @license   http://framework.zend.com/license/new-bsd New BSD License
 08   */
 09   
 10  namespace Zend\Stdlib\Hydrator\Strategy;
 11   
 12  use DateTime;
 13  use DateTimeZone;
 14   
 15  final class DateTimeFormatterStrategy implements StrategyInterface
 16  {
 17      /**
 18       * @var string
 19       */
 20      private $format;
 21   
 22      /**
 23       * @var DateTimeZone|null
 24       */
 25      private $timezone;
 26   
 27      /**
 28       * Constructor
 29       *
 30       * @param string            $format
 31       * @param DateTimeZone|null $timezone
 32       */
 33      public function __construct($format = DateTime::RFC3339, DateTimeZone $timezone = null)
 34      {
 35          $this->format   = (string) $format;
 36          $this->timezone = $timezone;
 37      }
 38   
 39      /**
 40       * {@inheritDoc}
 41       *
 42       * Converts to date time string
 43       *
 44       * @param mixed|DateTime $value
 45       *
 46       * @return mixed|string
 47       */
 48      public function extract($value)
 49      {
 50          if ($value instanceof DateTime) {
 51              return $value->format($this->format);
 52          }
 53   
 54          return $value;
 55      }
 56   
 57      /**
 58       * Converts date time string to DateTime instance for injecting to object
 59       *
 60       * {@inheritDoc}
 61       *
 62       * @param mixed|string $value
 63       *
 64       * @return mixed|DateTime
 65       */
 66      public function hydrate($value)
 67      {
 68          if ($value === '' || $value === null) {
 69              return;
 70          }
 71   
 72          if ($this->timezone) {
 73              $hydrated = DateTime::createFromFormat($this->format, $value, $this->timezone);
 74          } else {
 75              $hydrated = DateTime::createFromFormat($this->format, $value);
 76          }
 77   
 78          return $hydrated ?: $value;
 79      }
 80  }
 81