-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathch11p2DesignPatternTheory.php
More file actions
51 lines (41 loc) · 915 Bytes
/
ch11p2DesignPatternTheory.php
File metadata and controls
51 lines (41 loc) · 915 Bytes
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
<?php
include_once('generalIncludes.php');
echo '<input id="chapter" type="hidden" value="11">';
echo '<h2>Chapter 11 Elements of OO Design - Paragraph Design Pattern Theory</h2>';
echo '<h3>Listing 11.8: Singleton example</h3>';
showcode(<<<'CODE'
class DB
{
private static $_singleton;
private $_connection;
private function __construct($dsn) {
$this->_connection = new PDO($dsn);
}
public static function getInstance($dsn) {
if (is_null(self::$_singleton)) {
self::$_singleton = new DB($dsn);
}
return self::$_singleton;
}
}
$dsn = 'mysql:host=localhost;dbname=library';
$dsn = 'mysqli://test:test@localhost/testdb';
$db = DB::getInstance($dsn);
CODE
);
echo '<h3></h3>';
showcode(<<<'CODE'
CODE
);
echo '<h3></h3>';
showcode(<<<'CODE'
CODE
);
echo '<h3></h3>';
showcode(<<<'CODE'
CODE
);
echo '<h3></h3>';
showcode(<<<'CODE'
CODE
);