From 5111aae3e2db84c1831225db75bd490a2b02923b Mon Sep 17 00:00:00 2001 From: lopar Date: Sat, 3 Mar 2018 20:11:48 +0200 Subject: [PATCH] tests --- admin/test.php | 3 ++- classes/n.php | 22 ++++++++++++++++++++++ classes/nick.php | 8 ++++++-- 3 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 classes/n.php diff --git a/admin/test.php b/admin/test.php index 14b3454..b64c35c 100644 --- a/admin/test.php +++ b/admin/test.php @@ -15,4 +15,5 @@ print_r($row2); echo '
'; -$obj = new nick(11221); $obj->show(); \ No newline at end of file +n::show(11221)->show(); + diff --git a/classes/n.php b/classes/n.php new file mode 100644 index 0000000..a84832c --- /dev/null +++ b/classes/n.php @@ -0,0 +1,22 @@ + + * Project name: Battles-Game + */ + +class n +{ + private static $_instance = null; + + private function __clone() {} + private function __construct() {} + + public static function show($userId) + { + if (!self::$_instance) { + self::$_instance = battles\nick::search($userId); + } + return self::$_instance; + } +} \ No newline at end of file diff --git a/classes/nick.php b/classes/nick.php index 4ee7990..6b04ee7 100644 --- a/classes/nick.php +++ b/classes/nick.php @@ -4,7 +4,7 @@ * Author: Igor Barkov * Project name: Battles-Game */ - +namespace battles; class nick { private $user_data; @@ -14,7 +14,7 @@ class nick * nick constructor. * @param int $playerId */ - public function __construct($playerId) + private function __construct($playerId) { if (!$this->user_data) { $user = db::c()->query('SELECT `login`, `level`, `align`, (SELECT `short` FROM `clans` WHERE `clans`.`id` = `klan`) AS `klan`, `hp`, `maxhp` FROM `users` WHERE `id` = ?i', $playerId)->fetch_assoc(); @@ -23,6 +23,10 @@ class nick } + public static function search($playerId) + { + return new self($playerId); + } /** * @param int $showInvisibility