use class utils method

This commit is contained in:
Steffen Schröder 2014-05-13 16:15:46 +02:00
parent ef9c141786
commit 53504f984a
2 changed files with 9 additions and 42 deletions

View File

@ -2,6 +2,7 @@
namespace ManiaControl\Players; namespace ManiaControl\Players;
use ManiaControl\Utils\ClassUtil;
use ManiaControl\Utils\Formatter; use ManiaControl\Utils\Formatter;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
@ -252,7 +253,7 @@ class Player {
* @return mixed * @return mixed
*/ */
public function getCache($object, $cacheName) { public function getCache($object, $cacheName) {
$className = $this->getClassName($object); $className = ClassUtil::getClass($object);
if (isset($this->cache[$className . $cacheName])) { if (isset($this->cache[$className . $cacheName])) {
return $this->cache[$className . $cacheName]; return $this->cache[$className . $cacheName];
} }
@ -267,18 +268,18 @@ class Player {
* @param mixed $data * @param mixed $data
*/ */
public function setCache($object, $cacheName, $data) { public function setCache($object, $cacheName, $data) {
$className = $this->getClassName($object); $className = ClassUtil::getClass($object);
$this->cache[$className . $cacheName] = $data; $this->cache[$className . $cacheName] = $data;
} }
/** /**
* Destroys a Cache * Destroys a Cache
* *
* @param $object * @param mixed $object
* @param $cacheName * @param $cacheName
*/ */
public function destroyCache($object, $cacheName) { public function destroyCache($object, $cacheName) {
$className = $this->getClassName($object); $className = ClassUtil::getClass($object);
unset($this->cache[$className . $cacheName]); unset($this->cache[$className . $cacheName]);
} }
@ -328,22 +329,4 @@ class Player {
public function dumpCache() { public function dumpCache() {
var_dump($this->cache); var_dump($this->cache);
} }
/**
* 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;
}
} }

View File

@ -4,6 +4,7 @@ namespace ManiaControl\Players;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Utils\ClassUtil;
/** /**
* Player Data Manager * Player Data Manager
@ -136,7 +137,7 @@ class PlayerDataManager {
*/ */
public function defineMetaData($object, $dataName, $default, $dataDescription = '') { public function defineMetaData($object, $dataName, $default, $dataDescription = '') {
$mysqli = $this->maniaControl->database->mysqli; $mysqli = $this->maniaControl->database->mysqli;
$className = $this->getClassName($object); $className = ClassUtil::getClass($object);
$query = "INSERT INTO `" . self::TABLE_PLAYERDATAMETADATA . "` ( $query = "INSERT INTO `" . self::TABLE_PLAYERDATAMETADATA . "` (
`class`, `class`,
@ -168,23 +169,6 @@ class PlayerDataManager {
return true; return true;
} }
/**
* Get Class Name of a Parameter
*
* @param mixed $param
* @return string
*/
private function getClassName($param) {
if (is_object($param)) {
return get_class($param);
}
if (is_string($param)) {
return $param;
}
trigger_error('Invalid class param. ' . $param);
return (string)$param;
}
/** /**
* Get Type of a Parameter * Get Type of a Parameter
* *
@ -221,7 +205,7 @@ class PlayerDataManager {
* @return mixed|null * @return mixed|null
*/ */
public function getPlayerData($object, $dataName, Player $player, $serverIndex = -1) { public function getPlayerData($object, $dataName, Player $player, $serverIndex = -1) {
$className = $this->getClassName($object); $className = ClassUtil::getClass($object);
$meta = $this->metaData[$className . $dataName]; $meta = $this->metaData[$className . $dataName];
@ -278,7 +262,7 @@ class PlayerDataManager {
* @return bool * @return bool
*/ */
public function setPlayerData($object, $dataName, Player $player, $value, $serverIndex = -1) { public function setPlayerData($object, $dataName, Player $player, $value, $serverIndex = -1) {
$className = $this->getClassName($object); $className = ClassUtil::getClass($object);
if (!$player) { if (!$player) {
return false; return false;
} }