-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.php
More file actions
100 lines (78 loc) · 2.69 KB
/
cli.php
File metadata and controls
100 lines (78 loc) · 2.69 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
require_once './vendor/autoload.php';
use Utopia\CLI\CLI;
use Utopia\CLI\Console;
use Utopia\Database\Document;
use Utopia\Registry\Registry;
use Utopia\Validator\Wildcard;
use Utopia\Database\Database;
use Utopia\Cache\Cache;
use Utopia\Cache\Adapter\None as NoCache;
use Utopia\Database\Adapter\MySQL;
$register = new Registry();
$register->set('db', function () {
$dbHost = '127.0.0.1';
$dbPort = '33062';
$dbUser = 'root';
$dbPass = 'password';
return new PDO("mysql:host={$dbHost};port={$dbPort};charset=utf8mb4", $dbUser, $dbPass, [
PDO::ATTR_TIMEOUT => 3, // Seconds
PDO::ATTR_PERSISTENT => true,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_EMULATE_PREPARES => true,
PDO::ATTR_STRINGIFY_FETCHES => true
]);
});
$cli = new CLI();
$cli
->task('task1')
->param('email', null, new Wildcard())
->action(function ($email) {
Console::success($email);
Console::log('Plain Log'); // stdout
Console::success('Green log message'); // stdout
Console::info('Blue log message'); // stdout
Console::warning('Yellow log message'); // stderr
Console::error('Red log message'); // stderr
});
$cli
->task('load')
->action(function () use($register) {
Console::success('start'); // stdout
//
// $stdout = '';
// $stderr = '';
// $stdin = '123';
// $timeout = 3; // seconds
// $code = Console::execute('>&1 echo "success"', $stdin, $stdout, $stderr, $timeout);
//
// Console::log('$code=' . $code); // '0'
// Console::log('$stdout=' . $stdout); // 'success'
// Console::log('$stderr=' . $stderr); // ''
//
// Console::loop(function() {echo "Hello World\n";}, 10.1 );
//
$db = new Database(new MySQL($register->get('db')), new Cache(new NoCache()));
$db->setNamespace("ns");
$db->create('foo2');
$collection = $db->getCollection('shmuel');
if($collection->isEmpty()){
$collection = $db->createCollection('shmuel',[],[]);
}
try {
$db->createAttribute($collection->getId(), "title", "string", 100, true);
}
catch (Exception $e){
}
Console::loop(function() use ($collection, $db) {
Console::success('insert start ');
$doc = $db->createDocument($collection->getId(), new Document([
'title' => "this is a title ", //. rand(9999999999, 99999999999),
'$write' => ['role:all'],
'$read' => ['role:all']
]));
var_dump($doc);
}, 0.0000 );
});
$cli->run();