added classname to cache

This commit is contained in:
kremsy 2014-05-09 23:33:24 +02:00
parent 8646177531
commit 74320397ea

View File

@ -247,12 +247,14 @@ class Player {
/** /**
* Get the Cache with the given Name * Get the Cache with the given Name
* *
* @param $object
* @param string $cacheName * @param string $cacheName
* @return mixed * @return mixed
*/ */
public function getCache($cacheName) { public function getCache($object, $cacheName) {
if (isset($this->cache[$cacheName])) { $className = $this->getClassName($object);
return $this->cache[$cacheName]; if (isset($this->cache[$className . $cacheName])) {
return $this->cache[$className . $cacheName];
} }
return null; return null;
} }
@ -260,11 +262,13 @@ class Player {
/** /**
* Set the Cache Data for the given Name * Set the Cache Data for the given Name
* *
* @param $object
* @param string $cacheName * @param string $cacheName
* @param mixed $data * @param mixed $data
*/ */
public function setCache($cacheName, $data) { public function setCache($object, $cacheName, $data) {
$this->cache[$cacheName] = $data; $className = $this->getClassName($object);
$this->cache[$className . $cacheName] = $data;
} }
/** /**
@ -306,4 +310,23 @@ class Player {
public function dump() { public function dump() {
var_dump(json_decode(json_encode($this))); var_dump(json_decode(json_encode($this)));
} }
/**
* Get Class Name of a Parameter
*
* @param mixed $param
* @return string
*/
private function getClassName($param) {
//TODO move in a util or something
if (is_object($param)) {
return get_class($param);
}
if (is_string($param)) {
return $param;
}
trigger_error('Invalid class param. ' . $param);
return (string)$param;
}
} }