public function getConsts($prefix)
    {
        if (isset(self::$consts[$prefix])) {
            return self::$consts[$prefix];
        }

        // 1. Get all class constants
        $class = new \ReflectionClass($this);
        $consts = $class->getConstants();

        // 2. Use exiting constant configs
        $property = lcfirst(str_replace('_', '', ucwords($prefix, '_'))) . 'Table';
        if (isset($this->$property)) {
            $data = $this->$property;
        } else {
            $data = [];
        }

        // 3. Generate id and name
        $prefix .= '_';
        $length = strlen($prefix);
        foreach ($consts as $name => $id) {
            if (stripos($name, $prefix) !== 0) {
                continue;
            }
            if (in_array($name, $this->constExcludes)) {
                continue;
            }
            $data[$id]['id'] = $id;
            $data[$id]['name'] = strtolower(strtr(substr($name, $length), ['_' => '-']));
        }

        self::$consts[$prefix] = $data;

        return $data;
    }
public function getConsts($prefix)
    {
        if (isset(self::$consts[$prefix])) {
            return self::$consts[$prefix];
        }

        // 1. Get all class constants
        $class = new \ReflectionClass($this);
        $consts = $class->getConstants();

        // 2. Use exiting constant configs
        $property = lcfirst(str_replace('_', '', ucwords($prefix, '_'))) . 'Table';
        if (isset($this->$property)) {
            $data = $this->$property;
        } else {
            $data = [];
        }

        // 3. Generate id and name
        $prefix .= '_';
        $length = strlen($prefix);
        foreach ($consts as $name => $id) {
            if (stripos($name, $prefix) !== 0) {
                continue;
            }
            if (in_array($name, $this->constExcludes)) {
                continue;
            }
            $data[$id]['id'] = $id;
            $data[$id]['name'] = strtolower(strtr(substr($name, $length), ['_' => '-']));
        }

        self::$consts[$prefix] = $data;

        return $data;
    }
public function getConsts ( $ prefix ) { if ( isset ( self :: $ consts [ $ prefix ] ) ) { return self :: $ consts [ $ prefix ] ; } // 1. Get all class constants $ class = new \ ReflectionClass ( $ this ) ; $ consts = $ class -> getConstants ( ) ; // 2. Use exiting constant configs $ property = lcfirst ( str_replace ( '_' , '' , ucwords ( $ prefix , '_' ) ) ) . 'Table' ; if ( isset ( $ this -> $ property ) ) { $ data = $ this -> $ property ; } else { $ data = [ ] ; } // 3. Generate id and name $ prefix .= '_' ; $ length = strlen ( $ prefix ) ; foreach ( $ consts as $ name => $ id ) { if ( stripos ( $ name , $ prefix ) !== 0 ) { continue ; } if ( in_array ( $ name , $ this -> constExcludes ) ) { continue ; } $ data [ $ id ] [ 'id' ] = $ id ; $ data [ $ id ] [ 'name' ] = strtolower ( strtr ( substr ( $ name , $ length ) , [ '_' => '-' ] ) ) ; } self :: $ consts [ $ prefix ] = $ data ; return $ data ; }
Get constants table by prefix

@param string $prefix
@return array
Get constants table by prefix