$className) */ private static $constants = NULL; /** * Get constant * * Wrapper for Pseudoconstant methods. We use this so the calling function * doesn't need to know which class the Pseudoconstant is on * (some are on the Contribute_Pseudoconsant Class etc * * @access public * @static * * @param $constant * * @return array - array reference of all relevant constant */ public static function getConstant($constant) { $class = self::findConstantClass($constant); if ($class) { return $class::$constant(); } } /** * Flush constant * * Wrapper for Pseudoconstant methods. We use this so the calling function * doesn't need to know which class the Pseudoconstant is on * (some are on the Contribute_Pseudoconsant Class etc * * @access public * @static * * @param $constant * * @return array - array reference of all relevant constant */ public static function flushConstant($constant) { $class = self::findConstantClass($constant); if ($class) { $class::flush(lcfirst($constant)); //@todo the rule is api functions should only be called from within the api - we // should move this function to a Core class $name = _civicrm_api_get_entity_name_from_camel($constant); CRM_Core_OptionGroup::flush($name); return TRUE; } } /** * Determine where a constant lives * * If there's a full, preloaded map, use it. Otherwise, use search * class space. * * @param $constant * * @internal param string $name constant-name * @return string|NULL class-name */ public static function findConstantClass($constant) { if (self::$constants !== NULL && isset(self::$constants[$constant])) { return self::$constants[$constant]; } foreach (self::$constantClasses as $class) { if (method_exists($class, lcfirst($constant))) { return $class; } } return NULL; } /** * Scan for a list of pseudo-constants. A pseudo-constant is recognized by listing * any static properties which have corresponding static methods. * * This may be inefficient and should generally be avoided. * * @return array of string, constant names */ public static function findConstants() { if (self::$constants === NULL) { self::$constants = array(); foreach (self::$constantClasses as $class) { foreach (self::findConstantsByClass($class) as $constant) { self::$constants[$constant] = $class; } } } return array_keys(self::$constants); } /** * Scan for a list of pseudo-constants. A pseudo-constant is recognized by listing * any static properties which have corresponding static methods. * * This may be inefficient and should generally be avoided. * * @param $class * * @return array of string, constant names */ public static function findConstantsByClass($class) { $clazz = new ReflectionClass($class); $classConstants = array_intersect( CRM_Utils_Array::collect('name', $clazz->getProperties(ReflectionProperty::IS_STATIC)), CRM_Utils_Array::collect('name', $clazz->getMethods(ReflectionMethod::IS_STATIC)) ); return $classConstants; } /** * Flush all caches related to pseudo-constants. This may be inefficient * and should generally be avoided. * * @return void */ public static function flushAll() { foreach (self::findConstants() as $constant) { self::flushConstant($constant); } CRM_Core_PseudoConstant::flush(); } }