PHP Classes

File: classes/BasicEnum.php

Recommend this page to a friend!
  Classes of stefan   PHP XML Converter   classes/BasicEnum.php   Download  
File: classes/BasicEnum.php
Role: Class source
Content type: text/plain
Description: Class source
Class: PHP XML Converter
Transform Indesign to eBundesanzeiger XML format
Author: By
Last change:
Date: 1 year ago
Size: 1,033 bytes
 

Contents

Class file image Download
<?php
abstract class BasicEnum {
    private static
$constCacheArray = NULL;

    private static function
getConstants() {
        if (
self::$constCacheArray == NULL) {
           
self::$constCacheArray = [];
        }
       
$calledClass = get_called_class();
        if (!
array_key_exists($calledClass, self::$constCacheArray)) {
           
$reflect = new ReflectionClass($calledClass);
           
self::$constCacheArray[$calledClass] = $reflect->getConstants();
        }
        return
self::$constCacheArray[$calledClass];
    }

    public static function
isValidName($name, $strict = false) {
       
$constants = self::getConstants();

        if (
$strict) {
            return
array_key_exists($name, $constants);
        }

       
$keys = array_map('strtolower', array_keys($constants));
        return
in_array(strtolower($name), $keys);
    }

    public static function
isValidValue($value) {
       
$values = array_values(self::getConstants());
        return
in_array($value, $values, $strict = true);
    }
}
?>