added jsonserializable interface / trait

This commit is contained in:
kremsy 2017-04-04 19:40:19 +02:00
parent 738c7a134c
commit 527c37d006
12 changed files with 63 additions and 13 deletions

View File

@ -11,7 +11,7 @@
error_reporting(E_ALL); error_reporting(E_ALL);
// Run configuration // Run configuration
define('DEV_MODE', false); // Development mode to not send error reports etc. define('DEV_MODE', true); // Development mode to not send error reports etc.
define('LOG_NAME_USE_DATE', true); // Use current date as suffix for log file name in logs folder define('LOG_NAME_USE_DATE', true); // Use current date as suffix for log file name in logs folder
define('LOG_NAME_USE_PID', true); // Use current process id as suffix for log file name in logs folder define('LOG_NAME_USE_PID', true); // Use current process id as suffix for log file name in logs folder

View File

@ -10,6 +10,8 @@ use ManiaControl\Players\Player;
* @author ManiaControl Team <mail@maniacontrol.com> * @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014-2017 ManiaControl Team * @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*
* @deprecated see OnArmorEmptyStructure
*/ */
class ArmorEmptyStructure { class ArmorEmptyStructure {
/* /*

View File

@ -11,6 +11,8 @@ use ManiaControl\Players\Player;
* @author ManiaControl Team <mail@maniacontrol.com> * @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014-2017 ManiaControl Team * @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*
* @deprecated see Capture Structure
*/ */
class CaptureStructure { class CaptureStructure {
/* /*

View File

@ -3,6 +3,8 @@
namespace ManiaControl\Callbacks\Structures\Common; namespace ManiaControl\Callbacks\Structures\Common;
use ManiaControl\General\JsonSerializable;
use ManiaControl\General\JsonSerializeTrait;
use ManiaControl\General\UsageInformationAble; use ManiaControl\General\UsageInformationAble;
use ManiaControl\General\UsageInformationTrait; use ManiaControl\General\UsageInformationTrait;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
@ -14,8 +16,8 @@ use ManiaControl\ManiaControl;
* @copyright 2014-2017 ManiaControl Team * @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/ */
abstract class BaseStructure implements UsageInformationAble { abstract class BaseStructure implements UsageInformationAble, JsonSerializable {
use UsageInformationTrait; use UsageInformationTrait, JsonSerializeTrait;
/** @var ManiaControl $maniaControl */ /** @var ManiaControl $maniaControl */
protected $maniaControl; protected $maniaControl;

View File

@ -5,6 +5,8 @@ namespace ManiaControl\Callbacks\Structures\Common;
use ManiaControl\Callbacks\Structures\Common\Models\CommonPlayerScore; use ManiaControl\Callbacks\Structures\Common\Models\CommonPlayerScore;
use ManiaControl\Callbacks\Structures\ShootMania\Models\TeamScore; use ManiaControl\Callbacks\Structures\ShootMania\Models\TeamScore;
use ManiaControl\General\JsonSerializable;
use ManiaControl\General\JsonSerializeTrait;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
/** /**
@ -43,7 +45,7 @@ class CommonScoresStructure extends BaseStructure {
$teamScore = new \ManiaControl\Callbacks\Structures\ShootMania\Models\TeamScore(); $teamScore = new \ManiaControl\Callbacks\Structures\ShootMania\Models\TeamScore();
} }
$teamScore->setId($team->id); $teamScore->setTeamId($team->id);
$teamScore->setName($team->name); $teamScore->setName($team->name);
$teamScore->setRoundPoints($team->roundpoints); $teamScore->setRoundPoints($team->roundpoints);
$teamScore->setMatchPoints($team->matchpoints); $teamScore->setMatchPoints($team->matchpoints);

View File

@ -3,12 +3,21 @@
namespace ManiaControl\Callbacks\Structures\Common\Models; namespace ManiaControl\Callbacks\Structures\Common\Models;
use ManiaControl\General\JsonSerializable;
use ManiaControl\General\JsonSerializeTrait;
use ManiaControl\General\UsageInformationAble; use ManiaControl\General\UsageInformationAble;
use ManiaControl\General\UsageInformationTrait; use ManiaControl\General\UsageInformationTrait;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
class CommonPlayerScore implements UsageInformationAble { /**
use UsageInformationTrait; * Common PlayerStructure Model
*
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class CommonPlayerScore implements UsageInformationAble, JsonSerializable {
use UsageInformationTrait, JsonSerializeTrait;
protected $player; protected $player;
protected $rank; protected $rank;

View File

@ -2,6 +2,8 @@
namespace ManiaControl\Callbacks\Structures\Common\Models; namespace ManiaControl\Callbacks\Structures\Common\Models;
use ManiaControl\General\JsonSerializable;
use ManiaControl\General\JsonSerializeTrait;
use ManiaControl\General\UsageInformationAble; use ManiaControl\General\UsageInformationAble;
use ManiaControl\General\UsageInformationTrait; use ManiaControl\General\UsageInformationTrait;
@ -12,10 +14,10 @@ use ManiaControl\General\UsageInformationTrait;
* @copyright 2014-2017 ManiaControl Team * @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/ */
class CommonTeamScore implements UsageInformationAble { class CommonTeamScore implements UsageInformationAble, JsonSerializable {
use UsageInformationTrait; use UsageInformationTrait, JsonSerializeTrait;
private $id; private $teamId;
private $name; private $name;
private $roundPoints; private $roundPoints;
private $mapPoints; private $mapPoints;
@ -24,15 +26,15 @@ class CommonTeamScore implements UsageInformationAble {
/** /**
* @return mixed * @return mixed
*/ */
public function getId() { public function getTeamId() {
return $this->id; return $this->teamId;
} }
/** /**
* @param mixed $id * @param mixed $id
*/ */
public function setId($id) { public function setTeamId($id) {
$this->id = $id; $this->teamId = $id;
} }
/** /**

View File

@ -11,6 +11,8 @@ use ManiaControl\Players\Player;
* @author ManiaControl Team <mail@maniacontrol.com> * @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014-2017 ManiaControl Team * @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*
* @deprecated see OnNearMissStructure
*/ */
class NearMissStructure { class NearMissStructure {
/* /*

View File

@ -11,6 +11,8 @@ use ManiaControl\Players\Player;
* @author ManiaControl Team <mail@maniacontrol.com> * @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014-2017 ManiaControl Team * @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*
* @deprecated see OnPlayerHitStructure
*/ */
class PlayerHitStructure { class PlayerHitStructure {
/* /*

View File

@ -0,0 +1,12 @@
<?php
namespace ManiaControl\General;
/**
* Object implementing this Interface has a toJson() Method
*
* @package ManiaControl\General
*/
interface JsonSerializable {
public function toJson();
}

View File

@ -0,0 +1,14 @@
<?php
namespace ManiaControl\General;
/**
* Class DumpTrait Trait for Implementing the Methods for the JsonSerializeable Interface
*
* @package ManiaControl\General
*/
trait JsonSerializeTrait {
public function toJson(){
return json_encode(get_object_vars($this));
}
}

View File

@ -130,6 +130,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
* @see \ManiaControl\Plugins\Plugin::load() * @see \ManiaControl\Plugins\Plugin::load()
*/ */
public function load(ManiaControl $maniaControl) { public function load(ManiaControl $maniaControl) {
var_dump("tesst");
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Commands // Commands