-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathFactory#2.php
106 lines (99 loc) · 2.7 KB
/
Factory#2.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
abstract class UserData {
abstract public function getData():string;
}
class ExcelUserData extends UserData {
public function getData(): string
{
return 'User data for excel file';
}
}
class WordUserData extends UserData {
public function getData(): string
{
return 'User data for word file';
}
}
abstract class ProductData {
abstract public function getData():string;
}
class ExcelProductData extends ProductData {
public function getData(): string
{
return 'Product data for excel file';
}
}
class WordProductData extends ProductData {
public function getData(): string
{
return 'Product data for word file';
}
}
abstract class FileGenerator {
abstract function getHeaders(): string;
abstract function getUserContent(): string;
abstract function getProductContent(): string;
abstract function getFooter(): string;
}
class ExcelFileGenerator extends FileGenerator {
public function getHeaders(): string
{
return 'header for excel';
}
public function getUserContent(): string
{
$dataProvider = null;
$dataProvider = new ExcelUserData();
return $dataProvider->getData();
}
public function getProductContent(): string
{
$dataProvider = null;
$dataProvider = new ExcelProductData();
return $dataProvider->getData();
}
public function getFooter(): string
{
return 'footer for excel';
}
}
class WordFileGenerator extends FileGenerator {
public function getHeaders(): string
{
return 'header for word';
}
public function getUserContent(): string
{
$dataProvider = null;
$dataProvider = new WordUserData();
return $dataProvider->getData();
}
public function getProductContent(): string
{
$dataProvider = null;
$dataProvider = new WordProductData();
return $dataProvider->getData();
}
public function getFooter(): string
{
return 'footer for word';
}
}
//User
$fileGenerator = new ExcelFileGenerator;
var_dump($fileGenerator->getHeaders());
var_dump($fileGenerator->getUserContent());
var_dump($fileGenerator->getFooter());
$fileGenerator = new WordFileGenerator;
var_dump($fileGenerator->getHeaders());
var_dump($fileGenerator->getUserContent());
var_dump($fileGenerator->getFooter());
//Product
$fileGenerator = new ExcelFileGenerator;
var_dump($fileGenerator->getHeaders());
var_dump($fileGenerator->getProductContent());
var_dump($fileGenerator->getFooter());
$fileGenerator = new WordFileGenerator;
var_dump($fileGenerator->getHeaders());
var_dump($fileGenerator->getProductContent());
var_dump($fileGenerator->getFooter());