-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathphp_design_patterns.php
More file actions
executable file
·79 lines (67 loc) · 1.97 KB
/
php_design_patterns.php
File metadata and controls
executable file
·79 lines (67 loc) · 1.97 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
<?php
$br = (php_sapi_name() == "cli")? "":"<br>";
if(!extension_loaded('php_design_patterns')) {
dl('php_design_patterns.' . PHP_SHLIB_SUFFIX);
}
use PHPDesign\MacFactory;
use PHPDesign\WinFactory;
use PHPDesign\Book;
use PHPDesign\Kindle;
use PHPDesign\EbookAdapter;
use PHPDesign\HelloWorldService;
use PHPDesign\PlainTextFormatter;
use PHPDesign\HtmlFormatter;
use PHPDesign\Facade\Facade;
use PHPDesign\Facade\Bios;
use PHPDesign\Facade\Linux;
use PHPDesign\DI\DatabaseConfiguration;
use PHPDesign\DI\DatabaseConnection;
use PHPDesign\Commander\HelloCommand;
use PHPDesign\Commander\Invoker;
use PHPDesign\Commander\Receiver;
use PHPDesign\Commander\AddMessageDateCommand;
$macObj = new MacFactory();
$macObj->CreateButton();
$winObj = new WinFactory();
$winObj->CreateButton();
$bookObj = new Book();
$bookObj->open();
$bookObj->turnPage();
var_dump($bookObj->getPage());
$kindle = new Kindle();
$kindle->unlock();
$kindle->pressNext();
var_dump($kindle->getPage());
$ebookAdapter = new EbookAdapter(new Kindle());
$ebookAdapter->open();
$ebookAdapter->turnPage();
var_dump($ebookAdapter->getPage());
/* Bridge Patterns*/
$service = new HelloWorldService(new HtmlFormatter);
$service->get();
$service = new HelloWorldService(new PlainTextFormatter);
$service->get();
/* Facade Patterns */
$bios = new Bios();
$linux = new Linux();
$facade = new Facade($linux, $bios);
$facade->turnOn();
echo $facade->os->getName() . "\n";
$facade->turnOff();
echo "\n";
$configuration = new DatabaseConfiguration("127.9.0.1", "3306", "root", "1234");
$connection = new DatabaseConnection($configuration);
$connection->getDsn();
$invoker = new Invoker();
$receiver = new Receiver();
$invoker->setCommand(new HelloCommand($receiver));
$invoker->run();
var_dump($receiver->getOutput());
$messageDateCommand = new AddMessageDateCommand($receiver);
$messageDateCommand->execute();
$invoker->run();
var_dump($receiver->getOutput());
$messageDateCommand->undo();
$invoker->run();
var_dump($receiver->getOutput());
?>