|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace MisterIcy\ExcelWriter\Generator; |
|
5
|
|
|
|
|
6
|
|
|
use MisterIcy\ExcelWriter\Exceptions\GeneratorException; |
|
7
|
|
|
use MisterIcy\ExcelWriter\Handlers\HandlerInterface; |
|
8
|
|
|
use MisterIcy\ExcelWriter\Properties\PropertyCollection; |
|
9
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Defines an AbstractGenerator, the base of all Generators. |
|
13
|
|
|
* |
|
14
|
|
|
* @package MisterIcy\ExcelWriter\Generator |
|
15
|
|
|
* |
|
16
|
|
|
* @author Alexandros Koutroulis <[email protected]> |
|
17
|
|
|
* @license MIT |
|
18
|
|
|
*/ |
|
19
|
|
|
abstract class AbstractGenerator implements GeneratorInterface |
|
20
|
|
|
{ |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var HandlerInterface |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $handler; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var array |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $documentProperties; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var Spreadsheet |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $spreadsheet; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var PropertyCollection |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $properties; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var array |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $data; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @return PropertyCollection |
|
49
|
|
|
*/ |
|
50
|
|
|
public function getProperties(): PropertyCollection |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->properties; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param PropertyCollection $properties |
|
57
|
|
|
* @return AbstractGenerator |
|
58
|
|
|
*/ |
|
59
|
|
|
public function setProperties(PropertyCollection $properties): AbstractGenerator |
|
60
|
|
|
{ |
|
61
|
|
|
$this->properties = $properties; |
|
62
|
|
|
return $this; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param HandlerInterface $handler |
|
67
|
|
|
* @return HandlerInterface |
|
68
|
|
|
* @throws GeneratorException |
|
69
|
|
|
*/ |
|
70
|
|
|
public function setHandler(HandlerInterface $handler) : HandlerInterface |
|
71
|
|
|
{ |
|
72
|
|
|
if (null === $this->handler) { |
|
73
|
|
|
$this->handler = $handler; |
|
74
|
|
|
return $this->handler; |
|
75
|
|
|
} |
|
76
|
|
|
throw new GeneratorException("The base handler for this generator is already set"); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @return array |
|
81
|
|
|
*/ |
|
82
|
|
|
public function getDocumentProperties(): array |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->documentProperties; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @param array $documentProperties |
|
89
|
|
|
* @return AbstractGenerator |
|
90
|
|
|
*/ |
|
91
|
|
|
public function setDocumentProperties(array $documentProperties): AbstractGenerator |
|
92
|
|
|
{ |
|
93
|
|
|
$this->documentProperties = $documentProperties; |
|
94
|
|
|
return $this; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @return Spreadsheet |
|
99
|
|
|
*/ |
|
100
|
|
|
public function getSpreadsheet(): Spreadsheet |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->spreadsheet; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @return array |
|
107
|
|
|
*/ |
|
108
|
|
|
public function getData(): array |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->data; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @param array $data |
|
115
|
|
|
*/ |
|
116
|
|
|
public function setData(array $data): self |
|
117
|
|
|
{ |
|
118
|
|
|
$this->data = $data; |
|
119
|
|
|
return $this; |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|