1
|
|
|
<?php |
2
|
|
|
/** @noinspection PhpDocFieldTypeMismatchInspection */ |
3
|
|
|
|
4
|
|
|
|
5
|
|
|
namespace TournamentGenerator\Export\Hierarchy; |
6
|
|
|
|
7
|
|
|
use InvalidArgumentException; |
8
|
|
|
use TournamentGenerator\Export\Export; |
9
|
|
|
use TournamentGenerator\Export\ExportBase; |
10
|
|
|
use TournamentGenerator\Export\Single\GameExporter; |
11
|
|
|
use TournamentGenerator\Game; |
12
|
|
|
use TournamentGenerator\HierarchyBase; |
13
|
|
|
use TournamentGenerator\Interfaces\WithGames; |
14
|
|
|
use TournamentGenerator\Interfaces\WithId; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Exporter for games |
18
|
|
|
* |
19
|
|
|
* A specific exporter, taking care of games and their related data. Exports all games from a hierarchy object. |
20
|
|
|
* |
21
|
|
|
* @package TournamentGenerator\Export |
22
|
|
|
* @author Tomáš Vojík <[email protected]> |
23
|
|
|
* @since 0.5 |
24
|
|
|
*/ |
25
|
|
|
class GamesExporter extends ExportBase |
26
|
|
|
{ |
27
|
|
|
|
28
|
|
|
/** @var Game */ |
29
|
|
|
protected WithId $object; |
30
|
|
|
|
31
|
|
|
public function __construct(HierarchyBase $object) { |
32
|
|
|
if (!$object instanceof WithGames) { |
33
|
|
|
throw new InvalidArgumentException('Object must be instance of WithGames.'); |
34
|
|
|
} |
35
|
|
|
parent::__construct($object); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Simple export query without any modifiers |
40
|
|
|
* |
41
|
|
|
* @param HierarchyBase $object |
42
|
|
|
* |
43
|
|
|
* @return array |
44
|
|
|
*/ |
45
|
|
|
public static function export(WithId $object) : array { |
46
|
|
|
return self::start($object)->get(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Start an export query |
51
|
|
|
* |
52
|
|
|
* @param HierarchyBase $object |
53
|
|
|
* |
54
|
|
|
* @return Export |
55
|
|
|
*/ |
56
|
|
|
public static function start(WithId $object) : Export { |
57
|
|
|
return new self($object); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Gets the basic unmodified data |
62
|
|
|
* |
63
|
|
|
* @return array |
64
|
|
|
* @see GameExporter::export() |
65
|
|
|
* |
66
|
|
|
*/ |
67
|
|
|
public function getBasic() : array { |
68
|
|
|
return array_map(static function(Game $game) { |
69
|
|
|
return (object) GameExporter::exportBasic($game); |
70
|
|
|
}, $this->object->getGames()); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
} |