/** * Generate a Cache Key * @param object $object * @param string $method * @param array $arguments * @param string $prefix * @param string $suffix * @return string|md5 */ function zbase_cache_key($object = null, $method = null, array $arguments = null, $prefix = null, $suffix = null) { $strings = []; if (!empty($prefix)) { $strings[] = md5($prefix); } if (is_object($object)) { $strings[] = str_replace('\\', '_', get_class($object)); } if (!empty($method)) { $strings[] = $method; } if (is_array($arguments)) { $strings[] = zbase_string_from_array($arguments); } if (!empty($suffix)) { $strings[] = $suffix; } if (!empty($strings)) { return md5(str_slug(implode(' ', $strings))); } return null; }
/** * Create a string based from array * @param array $array * @param string $glue * @return string */ function zbase_string_from_array($array, $glue = '_') { $newArgs = []; if (empty($array)) { return null; } foreach ($array as $k => $v) { if (is_array($v)) { $newArgs[] = zbase_string_from_array($v); } else { if (!is_object($k) && is_object($v) && is_object($glue)) { $newArgs[] = $k . $glue . $v; } } } return implode($glue, $newArgs); }