]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | <?php\r |
2 | /**\r | |
3 | * @class SessionDB\r | |
4 | * Fake Database. Stores records in $_SESSION\r | |
5 | */\r | |
6 | class SessionDB {\r | |
7 | public function __construct() {\r | |
8 | if (!isset($_SESSION['pk'])) {\r | |
9 | $_SESSION['pk'] = 10; // <-- start fake pks at 10\r | |
10 | $_SESSION['rs'] = getData(); // <-- populate $_SESSION with data.\r | |
11 | }\r | |
12 | }\r | |
13 | // fake a database pk\r | |
14 | public function pk() {\r | |
15 | return $_SESSION['pk']++;\r | |
16 | }\r | |
17 | // fake a resultset\r | |
18 | public function rs() {\r | |
19 | return $_SESSION['rs'];\r | |
20 | }\r | |
21 | public function insert($rec) {\r | |
22 | array_push($_SESSION['rs'], $rec);\r | |
23 | }\r | |
24 | public function update($idx, $attributes) {\r | |
25 | $_SESSION['rs'][$idx] = $attributes;\r | |
26 | }\r | |
27 | public function destroy($idx) {\r | |
28 | return array_shift(array_splice($_SESSION['rs'], $idx, 1));\r | |
29 | }\r | |
30 | }\r | |
31 | \r | |
32 | // Sample data.\r | |
33 | function getData() {\r | |
34 | return array(\r | |
35 | array('id' => 1, 'first' => "Fred", 'last' => 'Flintstone', 'email' => 'fred@flintstone.com'),\r | |
36 | array('id' => 2, 'first' => "Wilma", 'last' => 'Flintstone', 'email' => 'wilma@flintstone.com'),\r | |
37 | array('id' => 3, 'first' => "Pebbles", 'last' => 'Flintstone', 'email' => 'pebbles@flintstone.com'),\r | |
38 | array('id' => 4, 'first' => "Barney", 'last' => 'Rubble', 'email' => 'barney@rubble.com'),\r | |
39 | array('id' => 5, 'first' => "Betty", 'last' => 'Rubble', 'email' => 'betty@rubble.com'),\r | |
40 | array('id' => 6, 'first' => "BamBam", 'last' => 'Rubble', 'email' => 'bambam@rubble.com')\r | |
41 | );\r | |
42 | }\r |