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

SerializableStrategy.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 3.44 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  use Zend\Stdlib\Exception\InvalidArgumentException;
013  use Zend\Serializer\Adapter\AdapterInterface as SerializerAdapter;
014  use Zend\Serializer\Serializer as SerializerFactory;
015   
016  class SerializableStrategy implements StrategyInterface
017  {
018      /**
019       * @var string|SerializerAdapter
020       */
021      protected $serializer;
022   
023      /**
024       * @var array
025       */
026      protected $serializerOptions = array();
027   
028      /**
029       *
030       * @param mixed $serializer string or SerializerAdapter
031       * @param mixed $serializerOptions
032       */
033      public function __construct($serializer, $serializerOptions = null)
034      {
035          $this->setSerializer($serializer);
036          if ($serializerOptions) {
037              $this->setSerializerOptions($serializerOptions);
038          }
039      }
040   
041      /**
042       * Serialize the given value so that it can be extracted by the hydrator.
043       *
044       * @param mixed $value The original value.
045       * @return mixed Returns the value that should be extracted.
046       */
047      public function extract($value)
048      {
049          $serializer = $this->getSerializer();
050          return $serializer->serialize($value);
051      }
052   
053      /**
054       * Unserialize the given value so that it can be hydrated by the hydrator.
055       *
056       * @param mixed $value The original value.
057       * @return mixed Returns the value that should be hydrated.
058       */
059      public function hydrate($value)
060      {
061          $serializer = $this->getSerializer();
062          return $serializer->unserialize($value);
063      }
064   
065      /**
066       * Set serializer
067       *
068       * @param  string|SerializerAdapter $serializer
069       * @return SerializableStrategy
070       */
071      public function setSerializer($serializer)
072      {
073          if (!is_string($serializer) && !$serializer instanceof SerializerAdapter) {
074              throw new InvalidArgumentException(sprintf(
075                  '%s expects either a string serializer name or Zend\Serializer\Adapter\AdapterInterface instance; '
076                  . 'received "%s"',
077                  __METHOD__,
078                  (is_object($serializer) ? get_class($serializer) : gettype($serializer))
079              ));
080          }
081          $this->serializer = $serializer;
082          return $this;
083      }
084   
085      /**
086       * Get serializer
087       *
088       * @return SerializerAdapter
089       */
090      public function getSerializer()
091      {
092          if (is_string($this->serializer)) {
093              $options = $this->getSerializerOptions();
094              $this->setSerializer(SerializerFactory::factory($this->serializer, $options));
095          } elseif (null === $this->serializer) {
096              $this->setSerializer(SerializerFactory::getDefaultAdapter());
097          }
098   
099          return $this->serializer;
100      }
101   
102      /**
103       * Set configuration options for instantiating a serializer adapter
104       *
105       * @param  mixed $serializerOptions
106       * @return SerializableStrategy
107       */
108      public function setSerializerOptions($serializerOptions)
109      {
110          $this->serializerOptions = $serializerOptions;
111          return $this;
112      }
113   
114      /**
115       * Get configuration options for instantiating a serializer adapter
116       *
117       * @return mixed
118       */
119      public function getSerializerOptions()
120      {
121          return $this->serializerOptions;
122      }
123  }
124