-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathFactory.php
59 lines (51 loc) · 1.05 KB
/
Factory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
abstract class Writer {
public abstract function headers();
public abstract function write(string $dataSet);
}
class ExcelWriter extends Writer{
public function headers()
{
echo 'XML';
}
public function write(string $dataSet)
{
echo "Excel: $dataSet";
}
}
class WordWriter extends Writer{
public function headers()
{
echo 'XML';
}
public function write(string $dataSet)
{
echo "Word: $dataSet";
}
}
class PDFWriter extends Writer{
public function headers()
{
echo 'binary';
}
public function write(string $dataSet)
{
echo "PDF: $dataSet";
}
}
class WriterFactory {
public static function make(string $type): Writer
{
switch ($type) {
case 'pdf':
return new PDFWriter;
case 'word':
return new WordWriter;
case 'excel':
return new ExcelWriter;
}
}
}
$writer = WriterFactory::make('pdf');
$write->header();
$write->write();