-
Notifications
You must be signed in to change notification settings - Fork 0
/
test2
executable file
·70 lines (49 loc) · 2.1 KB
/
test2
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
#!/usr/bin/env php
<?php declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
use BapCat\Persist\Drivers\Local\LocalDriver;
use BapCat\Phi\Phi;
use BapCat\Remodel\Registry;
use BapCat\Remodel\RemodelConnection;
use BapCat\Session\DatabaseSessionServiceProvider;
use BapCat\Session\DatabaseSessionStorage;
use BapCat\Session\SessionGateway;
use BapCat\Session\SessionManager;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\ConnectionInterface;
use Illuminate\Database\Query\Grammars\SQLiteGrammar;
use Illuminate\Database\Query\Processors\SQLiteProcessor;
use Illuminate\Database\Schema\Grammars\SQLiteGrammar as SQLiteSchemaGrammar;
$ioc = Phi::instance();
//-CONNECTION--------------------------------------------------------
$pdo = new PDO('sqlite::memory:');
$connection = new RemodelConnection($pdo, new SQLiteGrammar(), new SQLiteProcessor());
$connection->setSchemaGrammar(new SQLiteSchemaGrammar());
$connection->getSchemaBuilder()->create('sessions', function(Blueprint $table) use($connection): void {
$table->string('token', 64);
$table->string('data');
$table->timestamp('created_at')->default($connection->raw('CURRENT_TIMESTAMP'));
$table->timestamp('updated_at')->default($connection->raw('CURRENT_TIMESTAMP'));
$table->primary('token');
});
$ioc->bind(ConnectionInterface::class, $connection);
//-------------------------------------------------------------------
//-REMODEL-----------------------------------------------------------
$fs = new LocalDriver(__DIR__);
$cache = $fs->getDirectory('cache');
$remodel = new Registry($ioc, $cache);
$ioc->bind(Registry::class, $remodel);
//-------------------------------------------------------------------
$provider = new DatabaseSessionServiceProvider($ioc, $remodel);
$provider->register();
$provider->boot();
$manager = $ioc->make(SessionManager::class);
$gateway = $ioc->make(SessionGateway::class);
$manager->set('test', 'This is a test');
$manager->close();
$s1 = $gateway->query()->get();
$manager->open();
$manager->set('test', 'This is not a test');
$manager->close();
$s2 = $gateway->query()->get();
var_dump($s1, $s2);