Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added 'Phixd' dependency, and 'beforestore', 'afterfetch' events

  • Loading branch information...
commit 589796c39c010aed5cd763372b6bddd98fa11fc6 1 parent 6282b38
@cameronjacobson authored
View
6 .travis.yml
@@ -1,9 +1,9 @@
language: php
+
php:
- "5.4"
- - "5.3"
before_script:
- sudo apt-get install -y couchdb
- - wget http://getcomposer.org/composer.phar
- - php composer.phar install
+ - composer self-update
+ - composer install
View
3  composer.json
@@ -1,4 +1,7 @@
{
+ "require": {
+ "phixd/phixd": "1.0.*@dev"
+ },
"autoload": {
"psr-0": {
"Phreezer": "src/"
View
70 examples/events.php
@@ -0,0 +1,70 @@
+<?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';
+ }
+}
+
View
5 src/Phreezer/Storage.php
@@ -49,6 +49,7 @@
use Phreezer\Cache;
use Phreezer\LazyProxy;
use Phreezer\Util;
+use Phixd\Phixd;
abstract class Storage
{
@@ -108,6 +109,8 @@ public function store($object)
throw Util::getInvalidArgumentException(1, 'object');
}
+ Phixd::emit('beforestore', [$object]);
+
$this->doStore($this->freezer->freeze($object));
return $object->__phreezer_uuid;
@@ -138,7 +141,7 @@ public function fetch($id)
// Put object into the object cache.
Cache::put($id, $object);
}
-
+ Phixd::emit('afterfetch', [$object]);
return $object;
}
Please sign in to comment.
Something went wrong with that request. Please try again.