Adds a CharacterEventData class for events that are only character related.

This commit is contained in:
Vassyli
2018-01-04 13:02:57 +01:00
parent 003a6517ba
commit 41db0ddfda
2 changed files with 50 additions and 1 deletions
+46
View File
@@ -0,0 +1,46 @@
<?php
/**
* Created by PhpStorm.
* User: Basilius Sauter
* Date: 04.01.2018
* Time: 12:58
*/
namespace LotGD\Core\Events;
use LotGD\Core\Exceptions\ArgumentException;
use LotGD\Core\Models\Character;
/**
* Class CharacterEventData
* @package LotGD\Core\Events
*/
class CharacterEventData extends EventContextData
{
/**
* CharacterEventData constructor.
* @param array $data Must contain field character.
* @throws ArgumentException
*/
protected function __construct(array $data)
{
$mustHaveForm = ["character"];
$doesHaveForm = array_keys($data);
sort($mustHaveForm); sort($doesHaveForm);
if ($doesHaveForm !== $mustHaveForm) {
throw new ArgumentException("A new CharacterEventData event must have a character data field.");
}
if ($data["character"] instanceof Character === false) {
throw new ArgumentException(sprintf(
"data[character] must be an instance of %s, %s given.",
Character::class,
get_class($data["character"])
));
}
parent::__construct($data);
}
}
+4 -1
View File
@@ -3,10 +3,13 @@ declare(strict_types=1);
namespace LotGD\Core\Events;
use LotGD\Core\Exceptions\ArgumentException;
use LotGD\Core\Models\Viewpoint;
/**
* Class ViewpointDecorationEventData
* @package LotGD\Core\Events
*/
class ViewpointDecorationEventData extends EventContextData
{
/**