Пример #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
 /** 
  * 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;
 }
Пример #3
0
 /** 
  * Check if given input is of given type. 
  * @param mixed input 
  * @param string type 
  * @example isType('some text', 'string') - will return true 
  * @example isType('some text', 'object') - will return false  
  * @return boolean
  */
 public static function isType($input = false, $type = false)
 {
     if ($input && $type && Data::type($input) == $type) {
         return true;
     }
     return false;
 }
Пример #4
0
 /** 
  * Format anything into array. 
  * @param mixed input 
  * @return array 
  */
 public static function toArray($input = false)
 {
     if ($input) {
         switch (Data::type($input)) {
             case 'array':
                 $array = $input;
                 break;
             case 'object':
                 $array = self::arrayToObject($input);
                 break;
         }
         if (Validate::isObject($input)) {
             return $input;
         }
     }
     return false;
 }