protected function getObjectPersistenceInstance()
 {
     $objectPersistence = new ObjectPersistence();
     $objectPersistence->setBackend(new Memory());
     return $objectPersistence;
 }
Esempio n. 2
0
<?php

require '../vendor/autoload.php';
use ObjectPersistence\Backend\Memory\Memory;
use ObjectPersistence\ObjectPersistence;
use ObjectPersistence\Settings\Settings;
$settings = new Settings();
$settings->test = 'Hello World';
$settings->sub = new Settings();
$settings->sub->anotherTest = 'foo';
$settings->bar = 'lulz';
$objectPersistence = new ObjectPersistence();
$objectPersistence->setBackend(new Memory());
$id = $objectPersistence->save($settings);
$settings->sub = null;
$object = $objectPersistence->get($id);
print_r($object);
// sub is not null, cause the backend clones objects before saving
//$objectPersistence->update(100, new Settings);
<?php

chdir(__DIR__);
require '../vendor/autoload.php';
use ObjectPersistence\ObjectPersistence;
use ObjectPersistence\Settings\Settings;
use ObjectPersistence\Middleware\MiddlewareOptions;
class Test
{
}
$settings = new \Test();
$settings->test = 'test';
$backendSettings = new Settings(array('server' => 'mongodb://localhost:27017', 'database' => 'ObjectPersistence', 'collection' => 'Storage'));
$objectPersistence = new ObjectPersistence();
$backend = new \ObjectPersistence\Backend\MongoDB\MongoDB($backendSettings);
$objectPersistence->setBackend($backend);
$objectPersistence->addMiddleware(new \ObjectPersistence\Middleware\Cache\Cache());
$id = $objectPersistence->save($settings);
print_r($objectPersistence->get($id, new MiddlewareOptions(array('disabledMiddleware' => array('ObjectPersistence\\Middleware\\Cache\\Cache')))));