Пример #1
0
 /**
  * get value for cache key returning default value if key does not exist or is expired
  *
  * @error 16202
  * @param string $key expects the cache key name as string
  * @param null|mixed $default expects the default return value if cache key does not exist anymore
  * @return mixed|null
  */
 public function get($key, $default = null)
 {
     if (($value = apc_fetch(xapp_get_option(self::KEY_PREFIX, $this) . $key)) !== false) {
         return $value;
     } else {
         return xapp_default($default);
     }
 }
Пример #2
0
 /**
  * returns all listeners for specific event name or default value if event name is not found
  *
  * @error 10403
  * @param null|string $event expects the event name to lookup
  * @param mixed $default expects default return value
  * @return array|mixed
  */
 public static function listeners($event = null, $default = array())
 {
     if ($event !== null) {
         return isset(self::$_events[$event]) ? self::$_events[$event] : xapp_default($default);
     } else {
         return sizeof(self::$_events) > 0 ? self::$_events : xapp_default($default);
     }
 }
Пример #3
0
/**
 * xapp php < 5.3.0 compatible function to get property from class
 *
 * @param string|object $class expects the class name or object
 * @param string $property expects the property to get
 * @param null $default expects default return value
 * @return mixed|null
 */
function xapp_property_get($class, $property, $default = null)
{
    try {
        $property = new ReflectionProperty($class, $property);
        if ($property->isPublic()) {
            if ($property->isStatic()) {
                return $property->getValue();
            } else {
                if (is_object($class)) {
                    return $property->getValue($class);
                }
            }
        }
    } catch (Exception $e) {
    }
    return xapp_default($default);
}
Пример #4
0
 /**
  * get value for cache key returning default value if key does not exist or is expired
  *
  * @error 15802
  * @param string $key expects the cache key name as string
  * @param null|mixed $default expects the default return value if cache key does not exist anymore
  * @return null|mixed
  */
 public function get($key, $default = null)
 {
     if (($value = $this->_memcached->get(xapp_get_option(self::KEY_PREFIX, $this) . (string) $key)) !== false) {
         return $value;
     } else {
         return xapp_default($default);
     }
 }
Пример #5
0
 /**
  * get a value at a specific index if not not found will return default value of second parameter. if the
  * first parameter is not set will return the value of current index
  *
  * @see ArrayObject::offsetGet
  * @error 16304
  * @param null|mixed $index expects the optional index kex
  * @param null $default expects the optional default return value
  * @return mixed|null
  */
 public function get($index = null, $default = null)
 {
     if ($index === null) {
         return $this->current();
     } else {
         if ($this->offsetExists($index)) {
             return $this->offsetGet($index);
         } else {
             return xapp_default($default);
         }
     }
 }
Пример #6
0
 /**
  * get value for cache key returning default value if key does not exist or is expired
  *
  * @error 16203
  * @param string $key expects the cache key name as string
  * @param null|mixed|Exception $default expects the default return value or exception if cache key does not exist anymore
  * @return null|mixed
  * @throws Exception
  */
 public function get($key, $default = null)
 {
     if ($this->has($key)) {
         $php = @(include xapp_get_option(self::PATH, $this) . $this->keyify($key) . '.php');
         if ($php === false || time() >= (int) $php['lifetime']) {
             $this->forget($key);
             return xapp_default($default);
         } else {
             return $php['value'];
         }
     } else {
         return xapp_default($default);
     }
 }
Пример #7
0
 /**
  * merge array properties of a subclass by iterating through all parent classes
  * looking for the array property of the same name return merge value as array.
  * this function will leave all properties untouched which are not of type array
  *
  * @error 10611
  * @param string|object $object expects instance of class or class name as string
  * @param string $property expects the property name as string
  * @param null|mixed $default expects default return value if property does not exist
  * @return array|mixed|null
  */
 public static final function mergeProperty($object, $property, $default = null)
 {
     $p = null;
     $tmp = array();
     if (Xapp_Reflection::hasProperty($object, $property)) {
         $p = Xapp_Reflection::propertyFactory($object, $property);
         if (is_array($p)) {
             $tmp = $p;
         } else {
             return $p;
         }
     }
     if (get_parent_class($object) !== false) {
         $class = $object;
         while ($class = get_parent_class($class)) {
             if (xapp_property_exists($class, $property)) {
                 $p = Xapp_Reflection::propertyFactory($class, $property);
                 if (is_array($p)) {
                     $tmp = array_merge($tmp, $p);
                 }
             }
         }
     }
     return !empty($tmp) ? $tmp : xapp_default($default);
 }
Пример #8
0
 /**
  * get value for cache key returning default value if key does not exist or is expired
  *
  * @error 15503
  * @param string $key expects the cache key name as string
  * @param null|mixed $default expects the default return value if cache key does not exist anymore
  * @return null|mixed
  * @throws Xapp_Cache_Driver_Exception
  */
 public function get($key, $default = null)
 {
     if ($this->has($key)) {
         if (($value = file_get_contents(xapp_get_option(self::PATH, $this) . $this->filename($key))) !== false) {
             if (time() >= (int) substr($value, 0, 10)) {
                 $this->forget($key);
                 return xapp_default($default);
             } else {
                 return unserialize(substr(trim($value), 10));
             }
         } else {
             throw new Xapp_Cache_Driver_Exception(_("unable to read content from cache file"), 1550301);
         }
     } else {
         return xapp_default($default);
     }
 }
Пример #9
0
 /**
  * retrieve value from array by keys with dot notation e.g. config.database.user is equivalent
  * to a multidimensional array with same keys. pass a cache array in last parameter if there
  * is already a pre compiled cache array with array keys in dot notation. if so will retrieve
  * from cache array instead from first array which is needs to iterated until finally key
  * value is found. if no key is passed will return complete array
  *
  * @error 12411
  * @param array $array expects the original array to look for key
  * @param null|string $key expects the optional key to get from array
  * @param null|mixed $default expects optional returnable default value if key is not found
  * @param null|array $cache expects optional cache array for dot notation key => value pairs
  * @return array|null
  */
 protected static function out(array $array, $key = null, $default = null, array &$cache = null)
 {
     if ($key === null) {
         return $array;
     }
     if ($cache !== null && array_key_exists($key, $cache)) {
         return $cache[$key];
     }
     if ($cache !== null) {
         return $cache[$key] = xapp_array_get($array, $key, xapp_default($default));
     } else {
         return xapp_array_get($array, $key, xapp_default($default));
     }
 }
Пример #10
0
 /**
  * xapp option shortcut xapp_get_option single option getter to get option $key, the first parameter from $mixed the
  * second parameter returning third parameter $default if not found. the second parameter can be:
  * 1) array = returning options $key value if option exists in $mixed
  * 2) object = object instance implementing xapp option handling or not
  * 3) string = object class name as string to handle static classes/options
  * 4) null = null when called inside class for xapp option handling for auto caller determination
  *
  * @param null|string $key expects the options key name to get
  * @param null|object|string|array $mixed expects optional value according to explanation above
  * @param null|mixed $default expects the default return value
  * @return null|mixed the option key value
  */
 function xapp_get_option($key = null, &$mixed = null, $default = null)
 {
     if ($key !== null) {
         if (is_array($mixed)) {
             return array_key_exists($key, $mixed) ? $mixed[$key] : $default;
         } else {
             if (xapped()) {
                 return Xapp::getOption($key, $mixed, $default);
             } else {
                 if (is_object($mixed) && xapp_can_options($mixed)) {
                     return array_key_exists($key, $mixed->options) ? $mixed->options[$key] : $default;
                 } else {
                     if (is_string($mixed) && xapp_can_options($mixed)) {
                         return array_key_exists($key, $mixed::$options) ? $mixed::$options[$key] : $default;
                     }
                 }
             }
         }
     }
     return xapp_default($default);
 }