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

GuardUtils.php

Zuletzt modifiziert: 09.10.2024, 12:57 - Dateigröße: 2.49 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\Guard;
11   
12  use Traversable;
13   
14  /**
15   * Static guard helper class
16   *
17   * Bridges the gap for allowing refactoring until traits can be used by default.
18   *
19   * @deprecated
20   */
21  abstract class GuardUtils
22  {
23      const DEFAULT_EXCEPTION_CLASS = 'Zend\Stdlib\Exception\InvalidArgumentException';
24   
25      /**
26       * Verifies that the data is an array or Traversable
27       *
28       * @param  mixed  $data           the data to verify
29       * @param  string $dataName       the data name
30       * @param  string $exceptionClass FQCN for the exception
31       * @throws \Exception
32       */
33      public static function guardForArrayOrTraversable(
34          $data,
35          $dataName = 'Argument',
36          $exceptionClass = self::DEFAULT_EXCEPTION_CLASS
37      ) {
38          if (!is_array($data) && !($data instanceof Traversable)) {
39              $message = sprintf(
40                  '%s must be an array or Traversable, [%s] given',
41                  $dataName,
42                  is_object($data) ? get_class($data) : gettype($data)
43              );
44              throw new $exceptionClass($message);
45          }
46      }
47   
48      /**
49       * Verify that the data is not empty
50       *
51       * @param  mixed  $data           the data to verify
52       * @param  string $dataName       the data name
53       * @param  string $exceptionClass FQCN for the exception
54       * @throws \Exception
55       */
56      public static function guardAgainstEmpty(
57          $data,
58          $dataName = 'Argument',
59          $exceptionClass = self::DEFAULT_EXCEPTION_CLASS
60      ) {
61          if (empty($data)) {
62              $message = sprintf('%s cannot be empty', $dataName);
63              throw new $exceptionClass($message);
64          }
65      }
66   
67      /**
68       * Verify that the data is not null
69       *
70       * @param  mixed  $data           the data to verify
71       * @param  string $dataName       the data name
72       * @param  string $exceptionClass FQCN for the exception
73       * @throws \Exception
74       */
75      public static function guardAgainstNull(
76          $data,
77          $dataName = 'Argument',
78          $exceptionClass = self::DEFAULT_EXCEPTION_CLASS
79      ) {
80          if (null === $data) {
81              $message = sprintf('%s cannot be null', $dataName);
82              throw new $exceptionClass($message);
83          }
84      }
85  }
86