From de3bae902947170cf7005ac8d8a33332eef4a2de Mon Sep 17 00:00:00 2001 From: kremsy Date: Sun, 26 Mar 2017 12:42:20 +0200 Subject: [PATCH] proper scoping to callback structures + usage Information Method --- core/Callbacks/Structures/BaseStructure.php | 36 +++++++++++--- .../ManiaPlanet/StartEndStructure.php | 6 ++- .../ManiaPlanet/StartServerStructure.php | 4 +- .../Structures/ShootMania/Models/Landmark.php | 8 ++-- .../ShootMania/OnCaptureStructure.php | 25 +++------- .../ShootMania/OnCommandStructure.php | 26 +++++----- .../ShootMania/OnDefaultEventStructure.php | 8 +++- .../ShootMania/OnFallDamageStructure.php | 11 ++--- .../OnHitNearMissArmorEmptyStructure.php | 47 ++++++++++--------- .../OnPlayerRequestRespawnStructure.php | 18 +++---- .../ShootMania/OnScoresStructure.php | 43 +++++++++-------- .../ShootMania/OnShootStructure.php | 1 + .../ShootMania/OnShotDenyStructure.php | 33 ++++++------- .../TrackMania/OnCommandStructure.php | 28 ++++++----- .../TrackMania/OnDefaultEventStructure.php | 8 +++- .../XmlRpc/CallbacksListStructure.php | 2 + 16 files changed, 172 insertions(+), 132 deletions(-) diff --git a/core/Callbacks/Structures/BaseStructure.php b/core/Callbacks/Structures/BaseStructure.php index 0310d222..7ee3b33a 100644 --- a/core/Callbacks/Structures/BaseStructure.php +++ b/core/Callbacks/Structures/BaseStructure.php @@ -3,8 +3,8 @@ namespace ManiaControl\Callbacks\Structures; -use ManiaControl\General\Dumpable; use ManiaControl\ManiaControl; +use ReflectionClass; /** * Base Structure of all Callback Structures @@ -13,7 +13,7 @@ use ManiaControl\ManiaControl; * @copyright 2014-2017 ManiaControl Team * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 */ -abstract class BaseStructure implements Dumpable { +abstract class BaseStructure { /** @var ManiaControl $maniaControl */ protected $maniaControl; private $plainJsonObject; @@ -31,10 +31,34 @@ abstract class BaseStructure implements Dumpable { } /** - * Var_Dump the Structure + * Gets Information about the Class, and a List of the Public Method */ - public function dump() { - var_dump(json_decode(json_encode($this))); - var_dump("Class Name including Namespace: " . get_class($this)); + public function getUsage() { + $reflection = new ReflectionClass(get_class($this)); + echo $reflection->getDocComment(); + + echo "\nStructure Name of Class = " . get_class($this); + + echo "\nMethods:\n"; + + $metody = $reflection->getMethods(); + $methods = array_reverse($metody); + foreach ($methods as $key => $value) { + /** @var \ReflectionMethod $value */ + //Don't print the Constructor + if ($value->isPublic() && $value->getName() != "__construct" && $value->getName() != "getUsage") { + echo "\n\n"; + $txt = preg_replace('/\t/', '', $value->getDocComment()); + + echo $txt; + echo "\n \$result = " . $value->getName() . "();"; + $parameters = $value->getParameters(); + + foreach ($parameters as $parameter) { + echo "\n" . $parameter; + } + echo "\n"; + } + } } } \ No newline at end of file diff --git a/core/Callbacks/Structures/ManiaPlanet/StartEndStructure.php b/core/Callbacks/Structures/ManiaPlanet/StartEndStructure.php index 0b3c663e..3f4f8d0f 100644 --- a/core/Callbacks/Structures/ManiaPlanet/StartEndStructure.php +++ b/core/Callbacks/Structures/ManiaPlanet/StartEndStructure.php @@ -14,7 +14,7 @@ use ManiaControl\ManiaControl; * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 */ class StartEndStructure extends BaseStructure { - public $count; + private $count; public function __construct(ManiaControl $maniaControl, $data) { parent::__construct($maniaControl, $data); @@ -23,7 +23,9 @@ class StartEndStructure extends BaseStructure { } /** - * @return mixed + * Get the Count of this Section + * + * @return int */ public function getCount() { return $this->count; diff --git a/core/Callbacks/Structures/ManiaPlanet/StartServerStructure.php b/core/Callbacks/Structures/ManiaPlanet/StartServerStructure.php index 654c08a7..c3d2d6b8 100644 --- a/core/Callbacks/Structures/ManiaPlanet/StartServerStructure.php +++ b/core/Callbacks/Structures/ManiaPlanet/StartServerStructure.php @@ -14,7 +14,7 @@ use ManiaControl\ManiaControl; * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 */ class StartServerStructure extends BaseStructure { - public $restarted; + private $restarted; public function __construct(ManiaControl $maniaControl, $data) { parent::__construct($maniaControl, $data); @@ -23,6 +23,8 @@ class StartServerStructure extends BaseStructure { } /** + * Flag if the Server got Restarted + * * @return mixed */ public function getRestarted() { diff --git a/core/Callbacks/Structures/ShootMania/Models/Landmark.php b/core/Callbacks/Structures/ShootMania/Models/Landmark.php index bcf87d87..af562863 100644 --- a/core/Callbacks/Structures/ShootMania/Models/Landmark.php +++ b/core/Callbacks/Structures/ShootMania/Models/Landmark.php @@ -10,14 +10,14 @@ class Landmark { private $position = null; /** - * @return mixed + * @return string */ public function getTag() { return $this->tag; } /** - * @param mixed $tag + * @param string $tag */ public function setTag($tag) { $this->tag = $tag; @@ -52,14 +52,14 @@ class Landmark { } /** - * @return mixed + * @return \ManiaControl\Callbacks\Structures\ShootMania\Models\Position */ public function getPosition() { return $this->position; } /** - * @param mixed $position + * @param \ManiaControl\Callbacks\Structures\ShootMania\Models\Position $position */ public function setPosition(Position $position) { $this->position = $position; diff --git a/core/Callbacks/Structures/ShootMania/OnCaptureStructure.php b/core/Callbacks/Structures/ShootMania/OnCaptureStructure.php index 9b9d23b3..65a8e622 100644 --- a/core/Callbacks/Structures/ShootMania/OnCaptureStructure.php +++ b/core/Callbacks/Structures/ShootMania/OnCaptureStructure.php @@ -18,7 +18,7 @@ use ManiaControl\Players\Player; */ class OnCaptureStructure extends BaseStructure { - public $time; + private $time; private $landMark; private $playerArray = array(); @@ -44,23 +44,17 @@ class OnCaptureStructure extends BaseStructure { $this->landMark->setPosition($position); } - /** Dumps the Object with some Information */ - public function dump() { - var_dump($this->landMark); - parent::dump(); - } - /** - * Get the logins + * Get the logins as Array * - * @return array + * @return string[] */ public function getLoginArray() { return $this->playerArray; } /** - * Get the players + * Get the Players as Player Array * * @return Player[] */ @@ -76,16 +70,11 @@ class OnCaptureStructure extends BaseStructure { } /** - * @return LandMark + * Returns Information about the Captured Landmark + * + * @return \ManiaControl\Callbacks\Structures\ShootMania\Models\LandMark */ public function getLandMark() { return $this->landMark; } - - /** - * @param mixed $landMark - */ - public function setLandMark(Landmark $landMark) { - $this->landMark = $landMark; - } } \ No newline at end of file diff --git a/core/Callbacks/Structures/ShootMania/OnCommandStructure.php b/core/Callbacks/Structures/ShootMania/OnCommandStructure.php index 5140daaf..5a0a49a4 100644 --- a/core/Callbacks/Structures/ShootMania/OnCommandStructure.php +++ b/core/Callbacks/Structures/ShootMania/OnCommandStructure.php @@ -14,9 +14,9 @@ use ManiaControl\ManiaControl; * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 */ class OnCommandStructure extends BaseStructure { - public $time; - public $name; - public $value; + private $time; + private $name; + private $value; public function __construct(ManiaControl $maniaControl, $data) { parent::__construct($maniaControl, $data); @@ -26,13 +26,9 @@ class OnCommandStructure extends BaseStructure { $this->value = $this->getPlainJsonObject()->value; } - /** Dumps the Object with some Information */ - public function dump() { - parent::dump(); - var_dump("With getShooter() you get a Player Object"); - } - /** + * < Server time when the event occured + * * @return int */ public function getTime() { @@ -40,14 +36,22 @@ class OnCommandStructure extends BaseStructure { } /** - * @return mixed + * < Name of the command + * + * @return string */ public function getName() { return $this->name; } /** - * @return \ManiaControl\Players\Player + * < The value passed by the command + * "boolean": true, + * "integer": 123, + * "real": 123.456, + * "text": "an example value" + * + * @return mixed */ public function getValue() { return $this->value; diff --git a/core/Callbacks/Structures/ShootMania/OnDefaultEventStructure.php b/core/Callbacks/Structures/ShootMania/OnDefaultEventStructure.php index 9675bb49..d3ac0d51 100644 --- a/core/Callbacks/Structures/ShootMania/OnDefaultEventStructure.php +++ b/core/Callbacks/Structures/ShootMania/OnDefaultEventStructure.php @@ -14,8 +14,8 @@ use ManiaControl\ManiaControl; * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 */ class OnDefaultEventStructure extends BaseStructure { - public $time; - public $type; + private $time; + private $type; public function __construct(ManiaControl $maniaControl, $data) { parent::__construct($maniaControl, $data); @@ -25,6 +25,8 @@ class OnDefaultEventStructure extends BaseStructure { } /** + * Returns Server time when the event occured + * * @return int */ public function getTime() { @@ -32,6 +34,8 @@ class OnDefaultEventStructure extends BaseStructure { } /** + * Returns the type of event + * * @return string */ public function getType() { diff --git a/core/Callbacks/Structures/ShootMania/OnFallDamageStructure.php b/core/Callbacks/Structures/ShootMania/OnFallDamageStructure.php index c5bcc2d8..ee52c20f 100644 --- a/core/Callbacks/Structures/ShootMania/OnFallDamageStructure.php +++ b/core/Callbacks/Structures/ShootMania/OnFallDamageStructure.php @@ -15,7 +15,7 @@ use ManiaControl\Players\Player; * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 */ class OnFallDamageStructure extends BaseStructure { - public $time; + private $time; /** * @var Player $shooter */ @@ -29,6 +29,8 @@ class OnFallDamageStructure extends BaseStructure { } /** + * < Server time when the event occured + * * @return int */ public function getTime() { @@ -36,15 +38,12 @@ class OnFallDamageStructure extends BaseStructure { } /** + * < Player who fell + * * @return Player */ public function getVictim() { return $this->victim; } - /** Dumps the Object with some Information */ - public function dump() { - parent::dump(); - var_dump("With getVictim() you get a Player Object"); - } } \ No newline at end of file diff --git a/core/Callbacks/Structures/ShootMania/OnHitNearMissArmorEmptyStructure.php b/core/Callbacks/Structures/ShootMania/OnHitNearMissArmorEmptyStructure.php index 475ccef0..740e9c6b 100644 --- a/core/Callbacks/Structures/ShootMania/OnHitNearMissArmorEmptyStructure.php +++ b/core/Callbacks/Structures/ShootMania/OnHitNearMissArmorEmptyStructure.php @@ -17,15 +17,15 @@ use ManiaControl\Players\Player; * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 */ class OnHitNearMissArmorEmptyStructure extends BaseStructure { - public $time; - public $weapon; - public $damage; - public $distance = 0; //Note no distance on the OnHit and ArmorEmpty yet + private $time; + private $weapon; + private $damage; + private $distance = 0; //Note no distance on the OnHit and ArmorEmpty yet - private $shooterPosition; - private $victimPosition; - protected $shooter; - protected $victim; + private $shooterPosition; + private $victimPosition; + private $shooter; + private $victim; //private $shooterPoints; (was in mp3) //private $hitDistance; (was in mp3) @@ -43,7 +43,7 @@ class OnHitNearMissArmorEmptyStructure extends BaseStructure { $jsonObj = $this->getPlainJsonObject(); $this->time = $jsonObj->time; $this->weapon = $jsonObj->weapon; - $this->damage = $jsonObj->damage; + $this->damage = $jsonObj->damage; //TODO does only exist on onhit -> make baseclass $this->shooterPosition = new Position(); $this->shooterPosition->setX($jsonObj->shooterposition->x); @@ -63,18 +63,9 @@ class OnHitNearMissArmorEmptyStructure extends BaseStructure { $this->victim = $this->maniaControl->getPlayerManager()->getPlayer($this->getPlainJsonObject()->victim); } - /** Dumps the Object with some Information */ - public function dump() { - var_dump("Dump of property Shooter Position"); - var_dump($this->shooterPosition); - var_dump("Dump of property Victim Position"); - var_dump($this->victimPosition); - parent::dump(); - var_dump("With getShooter() you get a Player Object"); - var_dump("With getVictim() you get a Player Object"); - } - /** + * < Server time when the event occured + * * @return int */ public function getTime() { @@ -82,6 +73,9 @@ class OnHitNearMissArmorEmptyStructure extends BaseStructure { } /** + * < Id of the weapon [1-Laser, 2-Rocket, 3-Nucleus, 5-Arrow] + * + * @see \ManiaControl\Callbacks\Structures\ShootMania\Models\Weapons * @return int */ public function getWeapon() { @@ -89,6 +83,9 @@ class OnHitNearMissArmorEmptyStructure extends BaseStructure { } /** + * < Amount of Damage done by the hit (only on onHit) + * TODO base class and extend properties) + * * @return int */ public function getDamage() { @@ -96,7 +93,7 @@ class OnHitNearMissArmorEmptyStructure extends BaseStructure { } /** - * TODO Position Object + * < Position of the Shooter at the time * * @return Position */ @@ -105,15 +102,17 @@ class OnHitNearMissArmorEmptyStructure extends BaseStructure { } /** - * TODO Position Object + * < Position of the Victim at the time * - * @return Position + * @return \ManiaControl\Callbacks\Structures\ShootMania\Models\Position */ public function getVictimPosition() { return $this->victimPosition; } /** + * < Shooter Player + * * @return Player */ public function getShooter() { @@ -121,6 +120,8 @@ class OnHitNearMissArmorEmptyStructure extends BaseStructure { } /** + * < Victim Player + * * @return Player */ public function getVictim() { diff --git a/core/Callbacks/Structures/ShootMania/OnPlayerRequestRespawnStructure.php b/core/Callbacks/Structures/ShootMania/OnPlayerRequestRespawnStructure.php index ec086fe9..4419e9c5 100644 --- a/core/Callbacks/Structures/ShootMania/OnPlayerRequestRespawnStructure.php +++ b/core/Callbacks/Structures/ShootMania/OnPlayerRequestRespawnStructure.php @@ -15,9 +15,9 @@ use ManiaControl\Players\Player; * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 */ class OnPlayerRequestRespawnStructure extends BaseStructure { - public $time; + private $time; /** - * @var Player $shooter + * @var Player $player */ private $player; @@ -26,9 +26,13 @@ class OnPlayerRequestRespawnStructure extends BaseStructure { $this->time = $this->getPlainJsonObject()->time; $this->player = $this->maniaControl->getPlayerManager()->getPlayer($this->getPlainJsonObject()->login); + + $this->getUsage(); } /** + * Returns the Time the Event Happened + * * @return int */ public function getTime() { @@ -36,15 +40,11 @@ class OnPlayerRequestRespawnStructure extends BaseStructure { } /** - * @return Player + * Gets the Player + * + * @return \ManiaControl\Players\Player */ public function getPlayer() { return $this->player; } - - /** Dumps the Object with some Information */ - public function dump() { - parent::dump(); - var_dump("With getPlayer() you get a Player Object"); - } } \ No newline at end of file diff --git a/core/Callbacks/Structures/ShootMania/OnScoresStructure.php b/core/Callbacks/Structures/ShootMania/OnScoresStructure.php index b6c043a2..5f171665 100644 --- a/core/Callbacks/Structures/ShootMania/OnScoresStructure.php +++ b/core/Callbacks/Structures/ShootMania/OnScoresStructure.php @@ -6,7 +6,6 @@ namespace ManiaControl\Callbacks\Structures\ShootMania; use ManiaControl\Callbacks\Structures\BaseStructure; use ManiaControl\Callbacks\Structures\ShootMania\Models\TeamScore; use ManiaControl\ManiaControl; -use ManiaControl\Players\Player; /** * Structure Class for the OnScores Structure Callback @@ -16,13 +15,13 @@ use ManiaControl\Players\Player; * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 */ class OnScoresStructure extends BaseStructure { - public $responseId; - public $section; - public $useTeams; - public $winnerTeam; - public $winnerPlayer; + private $responseId; + private $section; + private $useTeams; + private $winnerTeam; + private $winnerPlayer; private $teamScores = array(); - public $players; //TODO implement + private $players; //TODO implement //TODO test public function __construct(ManiaControl $maniaControl, $data) { @@ -51,36 +50,36 @@ class OnScoresStructure extends BaseStructure { //TODO implement player } - /** Dumps the Object with some Information */ - public function dump() { - parent::dump(); - var_dump("With getWinnerPlayer() you get a Player Object"); - var_dump($this->teamScores); - } - - /** - * @return Player + * Get the Winner Player Object + * + * @return \ManiaControl\Players\Player */ public function getWinnerPlayer() { return $this->winnerPlayer; } /** - * @return mixed + * Get the Response Id + * + * @return string */ public function getResponseId() { return $this->responseId; } /** - * @return mixed + * < Current progress of the match. Can be "" | "EndRound" | "EndMap" | "EndMatch" + * + * @return string */ public function getSection() { return $this->section; } /** + * Returns if the GameMode uses Teams or not + * * @return boolean */ public function getUseTeams() { @@ -88,13 +87,17 @@ class OnScoresStructure extends BaseStructure { } /** + * Get the Winner Team Id + * * @return int */ - public function getWinnerTeam() { + public function getWinnerTeamId() { return $this->winnerTeam; } /** + * Returns the TeamScores + * * @return TeamScore[] */ public function getTeamScores() { @@ -102,6 +105,8 @@ class OnScoresStructure extends BaseStructure { } /** + * Get The Player Scores + * * @return mixed */ public function getPlayers() { diff --git a/core/Callbacks/Structures/ShootMania/OnShootStructure.php b/core/Callbacks/Structures/ShootMania/OnShootStructure.php index 2b3b69c5..5735c268 100644 --- a/core/Callbacks/Structures/ShootMania/OnShootStructure.php +++ b/core/Callbacks/Structures/ShootMania/OnShootStructure.php @@ -29,6 +29,7 @@ class OnShootStructure extends BaseStructure { $this->weapon = $this->getPlainJsonObject()->weapon; $this->shooter = $this->maniaControl->getPlayerManager()->getPlayer($this->getPlainJsonObject()->shooter); + } /** diff --git a/core/Callbacks/Structures/ShootMania/OnShotDenyStructure.php b/core/Callbacks/Structures/ShootMania/OnShotDenyStructure.php index 6b496d9d..9b652f9c 100644 --- a/core/Callbacks/Structures/ShootMania/OnShotDenyStructure.php +++ b/core/Callbacks/Structures/ShootMania/OnShotDenyStructure.php @@ -5,7 +5,6 @@ namespace ManiaControl\Callbacks\Structures\ShootMania; use ManiaControl\Callbacks\Structures\BaseStructure; use ManiaControl\ManiaControl; -use ManiaControl\Players\Player; /** @@ -16,12 +15,12 @@ use ManiaControl\Players\Player; * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 */ class OnShotDenyStructure extends BaseStructure { - public $time; - public $shooterWeapon; - public $victimWeapon; + private $time; + private $shooterWeapon; + private $victimWeapon; - protected $shooter; - protected $victim; + private $shooter; + private $victim; /** * Construct a new On Hit Structure @@ -41,14 +40,9 @@ class OnShotDenyStructure extends BaseStructure { $this->victim = $this->maniaControl->getPlayerManager()->getPlayer($this->getPlainJsonObject()->victim); } - /** Dumps the Object with some Information */ - public function dump() { - parent::dump(); - var_dump("With getShooter() you get a Player Object"); - var_dump("With getVictim() you get a Player Object"); - } - /** + * ServerTime The Event Happened //TODO add Trait for the Time Property + * * @return int */ public function getTime() { @@ -57,14 +51,18 @@ class OnShotDenyStructure extends BaseStructure { /** - * @return Player + * Gets the Shooter Player + * + * @return \ManiaControl\Players\Player */ public function getShooter() { return $this->shooter; } /** - * @return Player + * Gets the Victim Player + * + * @return \ManiaControl\Players\Player */ public function getVictim() { return $this->victim; @@ -78,7 +76,10 @@ class OnShotDenyStructure extends BaseStructure { } /** - * @return mixed + * Get the Victim Weapon + * + * @see \ManiaControl\Callbacks\Structures\ShootMania\Models\Weapons + * @return int */ public function getVictimWeapon() { return $this->victimWeapon; diff --git a/core/Callbacks/Structures/TrackMania/OnCommandStructure.php b/core/Callbacks/Structures/TrackMania/OnCommandStructure.php index dd8fc655..de56dd67 100644 --- a/core/Callbacks/Structures/TrackMania/OnCommandStructure.php +++ b/core/Callbacks/Structures/TrackMania/OnCommandStructure.php @@ -14,9 +14,9 @@ use ManiaControl\ManiaControl; * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 */ class OnCommandStructure extends BaseStructure { - public $time; - public $name; - public $value; + private $time; + private $name; + private $value; public function __construct(ManiaControl $maniaControl, $data) { parent::__construct($maniaControl, $data); @@ -26,13 +26,9 @@ class OnCommandStructure extends BaseStructure { $this->value = $this->getPlainJsonObject()->value; } - /** Dumps the Object with some Information */ - public function dump() { - parent::dump(); - var_dump("With getShooter() you get a Player Object"); - } - /** + * < Server time when the event occured + * * @return int */ public function getTime() { @@ -40,18 +36,24 @@ class OnCommandStructure extends BaseStructure { } /** - * @return mixed + * < Name of the command + * + * @return string */ public function getName() { return $this->name; } /** - * @return \ManiaControl\Players\Player + * < The value passed by the command + * "boolean": true, + * "integer": 123, + * "real": 123.456, + * "text": "an example value" + * + * @return mixed */ public function getValue() { return $this->value; } - - } \ No newline at end of file diff --git a/core/Callbacks/Structures/TrackMania/OnDefaultEventStructure.php b/core/Callbacks/Structures/TrackMania/OnDefaultEventStructure.php index 0d4abec8..98a01331 100644 --- a/core/Callbacks/Structures/TrackMania/OnDefaultEventStructure.php +++ b/core/Callbacks/Structures/TrackMania/OnDefaultEventStructure.php @@ -14,8 +14,8 @@ use ManiaControl\ManiaControl; * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 */ class OnDefaultEventStructure extends BaseStructure { - public $time; - public $type; + private $time; + private $type; public function __construct(ManiaControl $maniaControl, $data) { parent::__construct($maniaControl, $data); @@ -25,6 +25,8 @@ class OnDefaultEventStructure extends BaseStructure { } /** + * Returns Server time when the event occured + * * @return int */ public function getTime() { @@ -32,6 +34,8 @@ class OnDefaultEventStructure extends BaseStructure { } /** + * Returns the type of event + * * @return string */ public function getType() { diff --git a/core/Callbacks/Structures/XmlRpc/CallbacksListStructure.php b/core/Callbacks/Structures/XmlRpc/CallbacksListStructure.php index c37c3cc7..4c30bc5d 100644 --- a/core/Callbacks/Structures/XmlRpc/CallbacksListStructure.php +++ b/core/Callbacks/Structures/XmlRpc/CallbacksListStructure.php @@ -29,6 +29,8 @@ class CallbacksListStructure extends BaseStructure { $this->responseId = $this->getPlainJsonObject()->responseid; $this->callbacks = $this->getPlainJsonObject()->callbacks; + + $this->getUsage(); } /**