Example #1
0
 /**
  * Define some constants by reading a PHP array of keys and values.
  * Note that the constant names will always be uppercase.
  * By setting a "prefix" option, constant names can be "DB_*" for example.
  * If you've defined your own constants, you should call this function
  * without any parameters to update the cache of user-defined constants.
  *
  * @param Array $array optional array of constant names and values
  * @param Array $options optional settings such as "prefix" and "suffix"
  */
 public static function define_constants($array = array(), $options = array())
 {
     // Define some new constants
     foreach ($array as $key => $value) {
         $prefix = array_key($options, 'prefix', '');
         $suffix = array_key($options, 'suffix', '');
         if (is_array($value)) {
             $value = join(', ', $value);
         }
         $name = strtoupper($prefix . $key . $suffix);
         if (!defined($name)) {
             define($name, $value);
         }
     }
     // Update the cache of user-defined constants, and return it
     self::$constants = array_key(get_defined_constants(TRUE), 'user');
     return self::get_constants();
 }