/** * 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; }
/** * Set value(s) in session. * @param use params to move deeper into array * @param last param is the value you want to set * @example set('user', 'firstName', 'John') - set user's first name to 'John' * @return boolean */ public static function set() { $keys = func_get_args(); $session = $_SESSION; if (!empty($keys) && !empty($session)) { $s =& $session; foreach ($keys as $key => $value) { if ($key == Data::count($keys) - 1) { $s = $keys[Data::count($keys) - 1]; } else { if (!isset($s[$value])) { $s[$value] = array(); } if (isset($s[$value]) && is_array($s[$value])) { $s[$value] = $s[$value]; } $s =& $s[$value]; } } $_SESSION = $session; return true; } return false; }