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

MapNamingStrategy.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 2.31 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\NamingStrategy;
11   
12  use Zend\Stdlib\Exception\InvalidArgumentException;
13   
14  class MapNamingStrategy implements NamingStrategyInterface
15  {
16      /**
17       * Map for hydrate name conversion.
18       *
19       * @var array
20       */
21      protected $mapping = array();
22   
23      /**
24       * Reversed map for extract name conversion.
25       *
26       * @var array
27       */
28      protected $reverse = array();
29   
30      /**
31       * Initialize.
32       *
33       * @param array $mapping Map for name conversion on hydration
34       * @param array $reverse Reverse map for name conversion on extraction
35       */
36      public function __construct(array $mapping, array $reverse = null)
37      {
38          $this->mapping = $mapping;
39          $this->reverse = $reverse ?: $this->flipMapping($mapping);
40      }
41   
42      /**
43       * Safelly flip mapping array.
44       *
45       * @param  array                    $array Array to flip
46       * @return array                    Flipped array
47       * @throws InvalidArgumentException
48       */
49      protected function flipMapping(array $array)
50      {
51          array_walk($array, function ($value) {
52              if (!is_string($value) && !is_int($value)) {
53                  throw new InvalidArgumentException('Mapping array can\'t be flipped because of invalid value');
54              }
55          });
56   
57          return array_flip($array);
58      }
59   
60      /**
61       * Converts the given name so that it can be extracted by the hydrator.
62       *
63       * @param  string $name The original name
64       * @return mixed  The hydrated name
65       */
66      public function hydrate($name)
67      {
68          if (array_key_exists($name, $this->mapping)) {
69              return $this->mapping[$name];
70          }
71   
72          return $name;
73      }
74   
75      /**
76       * Converts the given name so that it can be hydrated by the hydrator.
77       *
78       * @param  string $name The original name
79       * @return mixed  The extracted name
80       */
81      public function extract($name)
82      {
83          if (array_key_exists($name, $this->reverse)) {
84              return $this->reverse[$name];
85          }
86   
87          return $name;
88      }
89  }
90