From 7998898692b3824e648de7808cc6db70db214243 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schro=CC=88der?= Date: Sun, 10 Nov 2013 03:07:45 +0100 Subject: [PATCH] - split up Tools class in several smaller classes SRP: Single Responsibility Principle! --- application/configs/authentication.xml | 2 +- application/core/manialinkUtil.php | 55 ++++++++++++++ application/core/player.php | 1 + application/core/timeFormatter.php | 54 +++++++++++++ application/core/tools.php | 101 ------------------------- 5 files changed, 111 insertions(+), 102 deletions(-) create mode 100644 application/core/manialinkUtil.php create mode 100644 application/core/timeFormatter.php diff --git a/application/configs/authentication.xml b/application/configs/authentication.xml index 38659bfb..8027ecd8 100644 --- a/application/configs/authentication.xml +++ b/application/configs/authentication.xml @@ -6,6 +6,7 @@ steeffeen + kremsy @@ -27,7 +28,6 @@ xcaliber eole fix - kremsy papychampy titishu wurstigewurst diff --git a/application/core/manialinkUtil.php b/application/core/manialinkUtil.php new file mode 100644 index 00000000..4ed9aab1 --- /dev/null +++ b/application/core/manialinkUtil.php @@ -0,0 +1,55 @@ +'); + $xml->addAttribute('version', '1'); + if ($id) { + $xml->addAttribute('id', $id); + } + return $xml; + } + + /** + * Add alignment attributes to an xml element + * + * @param SimpleXMLElement $xml + * @param string $halign + * @param string $valign + */ + public static function addAlignment(\SimpleXMLElement $xml, $halign = 'center', $valign = 'center2') { + if (!property_exists($xml, 'halign')) { + $xml->addAttribute('halign', $halign); + } + if (!property_exists($xml, 'valign')) { + $xml->addAttribute('valign', $valign); + } + } + + /** + * Add translate attribute to an xml element + * + * @param SimpleXMLElement $xml + * @param bool $translate + */ + public static function addTranslate(\SimpleXMLElement $xml, $translate = true) { + if (!property_exists($xml, 'translate')) { + $xml->addAttribute('translate', ($translate ? 1 : 0)); + } + } +} + +?> diff --git a/application/core/player.php b/application/core/player.php index f1fc1855..d0d9b798 100644 --- a/application/core/player.php +++ b/application/core/player.php @@ -35,6 +35,7 @@ class Player { public $rightLevel = 0; // TODO: usefull construct player without rpc info? + // TODO: check isFakePlayer (probably server itself also "fakeplayer") // TODO: add all attributes like, allies, clublink ... just make vardump on rpc infos // TODO: READ ADDITIONAL INFOS FROM DATABASE /** diff --git a/application/core/timeFormatter.php b/application/core/timeFormatter.php new file mode 100644 index 00000000..c277cf70 --- /dev/null +++ b/application/core/timeFormatter.php @@ -0,0 +1,54 @@ + 0 ? $hours . ':' : ''); + $format .= ($hours > 0 && $minutes < 10 ? '0' : '') . $minutes . ':'; + $format .= ($seconds < 10 ? '0' : '') . $seconds . ':'; + $format .= ($milliseconds < 100 ? '0' : '') . ($milliseconds < 10 ? '0' : '') . $milliseconds; + return $format; + } + + /** + * Formats the given time (seconds) to hh:mm:ss + * + * @param int $time + * @return string + */ + public static function formatTimeH($time) { + return gmdate("H:i:s", $seconds); + } + + /** + * Convert the given time (seconds) to mysql timestamp + * + * @param int $time + * @return string + */ + public static function formatTimestamp($time) { + return date("Y-m-d H:i:s", $time); + } +} + +?> diff --git a/application/core/tools.php b/application/core/tools.php index ce47b9e6..bfe7a1b4 100644 --- a/application/core/tools.php +++ b/application/core/tools.php @@ -27,52 +27,6 @@ class Tools { } } - /** - * Check if the given data describes a player - * - * @param array $player - * @return bool - */ - public static function isPlayer($player) { - if (!$player || !is_array($player)) return false; - if (!array_key_exists('PlayerId', $player) || !is_int($player['PlayerId']) || $player['PlayerId'] <= 0) return false; - return true; - } - - /** - * Convert the given time int to mysql timestamp - * - * @param int $time - * @return string - */ - public static function timeToTimestamp($time) { - return date("Y-m-d H:i:s", $time); - } - - /** - * Add alignment attributes to an xml element - * - * @param simple_xml_element $xml - * @param string $halign - * @param string $valign - */ - public static function addAlignment($xml, $halign = 'center', $valign = 'center2') { - if (!is_object($xml) || !method_exists($xml, 'addAttribute')) return; - if (!property_exists($xml, 'halign')) $xml->addAttribute('halign', $halign); - if (!property_exists($xml, 'valign')) $xml->addAttribute('valign', $valign); - } - - /** - * Add translate attribute to an xml element - * - * @param simple_xml_element $xml - * @param bool $translate - */ - public static function addTranslate($xml, $translate = true) { - if (!is_object($xml) || !method_exists($xml, 'addAttribute')) return; - if (!property_exists($xml, 'translate')) $xml->addAttribute('translate', ($translate ? 1 : 0)); - } - /** * Load a remote file * @@ -119,37 +73,6 @@ class Tools { return $result[1]; } - /** - * Formats the given time (milliseconds) - * - * @param int $time - * @return string - */ - public static function formatTime($time) { - if (!is_int($time)) $time = (int) $time; - $milliseconds = $time % 1000; - $seconds = floor($time / 1000); - $minutes = floor($seconds / 60); - $hours = floor($minutes / 60); - $minutes -= $hours * 60; - $seconds -= $hours * 60 + $minutes * 60; - $format = ($hours > 0 ? $hours . ':' : ''); - $format .= ($hours > 0 && $minutes < 10 ? '0' : '') . $minutes . ':'; - $format .= ($seconds < 10 ? '0' : '') . $seconds . ':'; - $format .= ($milliseconds < 100 ? '0' : '') . ($milliseconds < 10 ? '0' : '') . $milliseconds; - return $format; - } - - /** - * Formats the given time (seconds) to hh:mm:ss - * - * @param int $time - * @return string - */ - public static function formatTimeH($seconds) { - return gmdate("H:i:s", $seconds); - } - /** * Convert given data to real boolean * @@ -183,30 +106,6 @@ class Tools { } } - /** - * Converts the given boolean to an int representation - * - * @param bool $bool - * @return int - */ - public static function boolToInt($bool) { - return ($bool ? 1 : 0); - } - - /** - * Build new simple xml element - * - * @param string $name - * @param string $id - * @return \SimpleXMLElement - */ - public static function newManialinkXml($id = null) { - $xml = new \SimpleXMLElement(''); - $xml->addAttribute('version', '1'); - if ($id) $xml->addAttribute('id', $id); - return $xml; - } - /** * Load config xml-file *