/
run.php
executable file
·79 lines (62 loc) · 1.77 KB
/
run.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
#!/usr/bin/env php
<?php
require_once(dirname(__FILE__) . '/Link.php');
require_once(dirname(__FILE__) . '/LinkPeer.php');
define('DB_NAME', 'links');
$m = new Mongo();
$linkPeer = new LinkPeer($m->selectDb(DB_NAME));
// Ensure the db is empty
foreach ($linkPeer->fetchAll() as $link) {
$linkPeer->delete($link);
}
// Print the contens of the database
echo "> initial database values:\n";
foreach ($linkPeer->fetchByTag('com') as $link) {
echo "$link\n";
}
echo "\n----\n";
// Add some links
$lnk1 = new Link();
$lnk1->setUrl('http://www.google.com');
$lnk1->addTag('google');
$lnk1->addTag('com');
$lnk2 = new Link();
$lnk2->setUrl('http://www.mongodb.org');
$lnk2->addTag('mongodb');
$lnk2->addTag('org');
$lnk3 = new Link();
$lnk3->setUrl('http://www.ibuildings.com');
$lnk3->addTag('ibuildings');
$lnk3->addTag('com');
$lnk4 = new Link();
$lnk4->setUrl('http://techportal.ibuildings.com/');
$lnk4->addTag('techportal');
$lnk4->addTag('ibuildings');
$lnk4->addTag('com');
$linkPeer->insert($lnk1);
$linkPeer->insert($lnk2);
$linkPeer->insert($lnk3);
$linkPeer->insert($lnk4);
// Print the entire database
echo "> new entire database :\n";
foreach ($linkPeer->fetchAll() as $link) {
echo "$link\n";
}
echo "\n----\n";
// Print the techportal link
echo "> retrieve the techportal link:\n";
echo $linkPeer->fetchByUrl('http://techportal.ibuildings.com/');
echo "\n----\n";
// Print all com tagged links
echo "> retrieve all 'com' tagged links:\n";
foreach ($linkPeer->fetchByTag('com') as $link) {
echo "$link\n";
}
echo "----\n";
// Update the techportal link and print
$lnk4->addTag('mongo');
$linkPeer->update($lnk4);
// Print the techportal link
echo "> retrieve the updated techportal link:\n";
echo $linkPeer->fetchByUrl('http://techportal.ibuildings.com/');
echo "\n----\n";