-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
144 lines (112 loc) · 3.13 KB
/
Copy pathindex.php
File metadata and controls
144 lines (112 loc) · 3.13 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
use Adapter\DataAdapter;
use Adapter\DataService;
use Command\Message;
use Command\Messenger\Email;
use Command\Messenger\SMS;
use Decorator\Invoice;
use Decorator\Items\Apartment;
use Decorator\Items\Car;
use Facade\AuthenticationFacadeService;
use FactoryMethod\Stationery\Factory\GraphiteStationeryFactory;
use FactoryMethod\Stationery\Factory\WoodStationeryFactory;
use Observer\Publisher;
use Observer\Service\MailService;
use Observer\Service\PushNotificationService;
use Observer\Service\SMSService;
use Proxy\ReadFileProxy;
use singleton\DatabaseConnection;
use Strategy\Gateway\Mellat;
use Strategy\Payment;
require __DIR__ . '/vendor/autoload.php';
//Strategy
echo '<br>';
echo 'Strategy Pattern';
echo '<br>';
$payment = new Payment();
$payment->setGateway(new Mellat());
$payment->initPayment(['userId' => 123]);
$payment->verifyPayment(['paymentId' => 123]);
//Observer
echo '<br>';
echo 'Observer Pattern';
echo '<br>';
$MailService = new MailService();
$smsService = new SMSService();
$PushNotificationService = new PushNotificationService();
$publisher = new Publisher();
$publisher->attach($MailService);
$publisher->attach($smsService);
$publisher->attach($PushNotificationService);
$publisher->setEvent('Run something...');
$publisher->detach($smsService);
$publisher->detach($PushNotificationService);
$publisher->setEvent('Run another event...');
//Decorator
echo '<br>';
echo 'Decorator Pattern';
echo '<br>';
$invoice = new Invoice();
$invoice = new Car($invoice);
$invoice = new Apartment($invoice);
var_dump($invoice->totalPrice(), '<br>', $invoice->items());
//FactoryMethod
echo '<br>';
echo 'FactoryMethod Pattern';
echo '<br>';
$factory = new WoodStationeryFactory();
$pencil = $factory->createPencil();
echo $pencil->getMaterial(); // Wood
echo '<br>';
$eraser = $factory->createEraser();
echo $eraser->getMaterial(); // Rubber
echo '<br>';
$factory = new GraphiteStationeryFactory();
$pencil = $factory->createPencil();
echo $pencil->getMaterial(); // Graphite
echo '<br>';
$eraser = $factory->createEraser();
echo $eraser->getMaterial(); // Plastic
echo '<br>';
// Singleton
echo '<br>';
echo 'Singleton Pattern';
echo '<br>';
$DBConnection1 = DatabaseConnection::getInstance();
$DBConnection2 = DatabaseConnection::getInstance();
var_dump($DBConnection1, $DBConnection2);
//Command
echo '<br>';
echo 'Command Pattern';
echo '<br>';
$message = new Message();
$message->addMessage( new SMS() );
$message->addMessage( new Email() );
$message->executeMessage();
//Adapter
echo '<br>';
echo 'Adapter Pattern';
echo '<br>';
$data = [
'name' => 'erfan',
'phone' => '0123456789',
'email' => 'erfantakdev@gmail.com'
];
$dataService = new DataService();
$dataAdapter = new DataAdapter($dataService);
$dataAdapter->setData($data);
$dataService->showData();
//Adapter
echo '<br>';
echo 'Adapter Pattern';
echo '<br>';
$Authentication = new AuthenticationFacadeService();
$Authentication->createAccount('User Data');
//Adapter
echo '<br>';
echo 'Adapter Pattern';
echo '<br>';
$fileOne = new ReadFileProxy('fileOne.txt');
$fileTwo = new ReadFileProxy('fileTwo.txt');
$fileOne = $fileOne->lazyLoad();
echo $fileOne->getContents();