protected function get_set($key = null, $set_value = null, &$value)
 {
     $key = $this->prepare_key($key);
     if ($set_value === null) {
         // get
         return tf_stripslashes_deep_keys($key === null ? $value : tf_akg($key, $value));
     } else {
         // set
         tf_aks($key, tf_addslashes_deep_keys($set_value), $value);
     }
 }
Exemple #2
0
 public function set($key, $value)
 {
     $this->start_session();
     tf_aks($key, $value, $_SESSION);
 }
 /**
  * @param $keys
  * @param $keysDelimiter
  * @param $loadCallback
  * @return false|mixed
  */
 public static function get($keys, $loadCallback = null, $keysDelimiter = '/')
 {
     $keys = (string) $keys;
     $keysArr = explode($keysDelimiter, $keys);
     $key = $keysArr;
     $key = array_shift($key);
     if ($key === '') {
         trigger_error('First key must not be empty', E_USER_ERROR);
     }
     $value = tf_akg($keys, self::$cache, null, $keysDelimiter);
     self::freeMemory();
     // call it every time to take care about memory
     if ($value === false) {
         return $value;
     }
     // already tried to load once
     if ($value === null) {
         $parameters = array('key' => $key, 'keys' => $keys, 'keys_arr' => $keysArr);
         if (is_callable($loadCallback)) {
             call_user_func_array($loadCallback, array($parameters));
         } else {
             do_action('tf_load_cache', $parameters);
         }
         unset($parameters);
         // try again to get value (maybe someone loaded it)
         $value = tf_akg($keys, self::$cache, null, $keysDelimiter);
         if ($value === null) {
             // no one loaded it (or not exists), set it to false, so next time to not try to load it
             tf_aks($keys, false, self::$cache, $keysDelimiter);
             return false;
         }
     }
     return $value;
 }
/**
* Set (or create if not exists) value for specified key in some keys level
*
* TEST:
   $test = array();
   tf_aks('a.b', 2, $test);
   tf_aks('a.b.c', 3, $test);
   tf_aks('a.c', array('test'), $test);
   tf_print($test);
   tf_print( tf_akg('a.b', $test) );
*/
function tf_aks($keys, $value, &$arrayOrObject, $keysDelimiter = '.')
{
    if (is_string($keys) || is_int($keys)) {
        $keys = explode($keysDelimiter, (string) $keys);
    }
    $keyOrProperty = array_shift($keys);
    if ($keyOrProperty === NULL) {
        return;
    }
    $isObject = is_object($arrayOrObject);
    if ($isObject) {
        if (!property_exists($arrayOrObject, $keyOrProperty) || !(is_array($arrayOrObject->{$keyOrProperty}) || is_object($arrayOrObject->{$keyOrProperty}))) {
            if ($keyOrProperty === '') {
                // this happens when use 'empty keys' like: abc.d.e....i.j..foo.
                trigger_error('Cannot push value to object like in array ($arr[] = $val)', E_USER_WARNING);
            } else {
                $arrayOrObject->{$keyOrProperty} = array();
            }
        }
    } else {
        if (!isset($arrayOrObject[$keyOrProperty]) || !is_array($arrayOrObject[$keyOrProperty])) {
            if ($keyOrProperty === '') {
                // this happens when use 'empty keys' like: abc.d.e....i.j..foo.
                $arrayOrObject[] = array();
                // get auto created key (last)
                end($arrayOrObject);
                $keyOrProperty = key($arrayOrObject);
            } else {
                $arrayOrObject[$keyOrProperty] = array();
            }
        }
    }
    if (isset($keys[0])) {
        // not used count() for performance reasons
        if ($isObject) {
            tf_aks($keys, $value, $arrayOrObject->{$keyOrProperty});
        } else {
            tf_aks($keys, $value, $arrayOrObject[$keyOrProperty]);
        }
    } else {
        if ($value !== null) {
            if ($isObject) {
                $arrayOrObject->{$keyOrProperty} = $value;
            } else {
                $arrayOrObject[$keyOrProperty] = $value;
            }
        } else {
            if ($isObject) {
                unset($arrayOrObject->{$keyOrProperty});
            } else {
                unset($arrayOrObject[$keyOrProperty]);
            }
        }
    }
}
Exemple #5
0
 public final function setSqlData($dotKey = null, $value)
 {
     if ($dotKey === null) {
         $this->sqlData = $value;
     } else {
         tf_aks($dotKey, $value, $this->sqlData, '/');
     }
 }