Adds a CharacterEventData class for events that are only character related.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user