示例#1
0
 /** 
  * Set value(s) in config. 
  * @param use params to move deeper into array 
  * @param last param is the value you want to set 
  * @example set('meta', 'title', 'Great title') - set meta title to 'Great title'
  * @return boolean
  */
 public static function set()
 {
     $keys = func_get_args();
     $config = self::getConfig();
     if (!empty($keys) && !empty($config)) {
         $c =& $config;
         foreach ($keys as $key => $value) {
             if ($key == Data::count($keys) - 1) {
                 $c = $keys[Data::count($keys) - 1];
             } else {
                 if (!isset($c[$value])) {
                     $c[$value] = array();
                 }
                 if (isset($c[$value]) && is_object($c[$value])) {
                     $c[$value] = Format::objectToArray($c[$value]);
                 }
                 $c =& $c[$value];
             }
         }
         $configJson = Format::toJson($config, true);
         if (isset(self::$config)) {
             self::$config = $config;
         }
         if (File::write('../config/custom.config.json', $configJson)) {
             return true;
         }
     }
     return false;
 }
示例#2
0
 /** 
  * Return a random value from a given array or object. 
  * @param array || object
  * @return string random value
  */
 public static function random($data = false)
 {
     if ($data) {
         if (Validate::isObject($data)) {
             $data = Format::objectToArray($data);
         }
         if (Validate::isArray($data)) {
             return $data[array_rand($data, 1)];
         }
     }
     return false;
 }