PluginProbe
Cookie Consent – GDPR & CCPA Cookie Banner & Consent Manager / trunk
Cookie Consent – GDPR & CCPA Cookie Banner & Consent Manager vtrunk
0.0.11 0.0.10 0.0.9 0.0.8 0.0.7 0.0.6 trunk 0.0.1 0.0.2 0.0.3 0.0.4 0.0.5
cookiez / classes / basic-enum.php

basic-enum.php in Cookie Consent – GDPR & CCPA Cookie Banner & Consent Manager trunk, at classes/basic-enum.php

47 lines 940 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Cookiez\Classes;
4
5 use ReflectionClass;
6 use ReflectionException;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 abstract class Basic_Enum {
13 private static array $entries = [];
14
15 /**
16 * @throws ReflectionException
17 */
18 public static function get_values(): array {
19 return array_values( self::get_entries() );
20 }
21
22 /**
23 * Whether the given value is a defined enum member.
24 *
25 * @param mixed $value
26 * @return bool
27 * @throws ReflectionException
28 */
29 public static function is_valid( $value ): bool {
30 return in_array( $value, self::get_values(), true );
31 }
32
33 /**
34 * @throws ReflectionException
35 */
36 protected static function get_entries(): array {
37 $caller = get_called_class();
38
39 if ( ! array_key_exists( $caller, self::$entries ) ) {
40 $reflect = new ReflectionClass( $caller );
41 self::$entries[ $caller ] = $reflect->getConstants();
42 }
43
44 return self::$entries[ $caller ];
45 }
46 }
47