-
Notifications
You must be signed in to change notification settings - Fork 0
/
events.php
70 lines (54 loc) · 1.28 KB
/
events.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
<?php
// Shows how to use 'Phixd' events
// There are currently 2 events fired inside Phreezer\Storage
// -beforestore
// -afterfetch
require_once(dirname(__DIR__).'/vendor/autoload.php');
use Phreezer\Storage\CouchDB;
use Phixd\Phixd;
$lazyProxy = false;
$blacklist = array();
$useAutoload = true;
$start = microtime(true);
$couch = new CouchDB([
'database' => 'mydb',
'user' => 'cameron',
'pass' => 'cameron'
]);
Phixd::on('beforestore', function($obj){
echo 'BEFORE STORE: '.$obj->c.PHP_EOL;
});
Phixd::on('afterfetch', function($obj){
echo 'AFTER FETCH: '.$obj->b.PHP_EOL;
});
$obj = new blah();
$obj->a = 1+$x;
$obj->b = 2+$x;
$obj->c = 3+$x;
echo 'STORING RECORD: ';
$id = $couch->store($obj);
echo $id.PHP_EOL;
echo PHP_EOL;
echo 'FETCHING: '.$id.PHP_EOL;
$obj = $couch->fetch($id);
echo 'UPDATING: '.$obj->a.' TO "'.$obj->blah().'"'.PHP_EOL;
$obj->a = $obj->blah();
echo 'STORING UPDATED VERSION OF: '.$id.PHP_EOL;
$couch->store($obj);
echo PHP_EOL;
echo 'FETCHING: '.$id.PHP_EOL;
$obj = $couch->fetch($id);
echo 'DELETING: '.$id.PHP_EOL;
$obj->_delete = true;
$couch->store($obj);
echo PHP_EOL;
echo 'COMPLETED IN: '.(microtime(true)-$start).' SECONDS'.PHP_EOL;
class blah
{
public $a;
public $b;
public $c;
public function blah(){
return 'blahblah';
}
}