Skip to content

Commit 11da1ab

Browse files
committed
console
CONSOLE
1 parent 75c82a1 commit 11da1ab

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

bin/kdbv

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,93 @@
11
#!/usr/bin/env php
22
<?php
33

4+
namespace kanduganesh;
5+
6+
//print_r(parse_url('mysql://[[softdbuser]]:[[softdbpass]]@[[softdbhost]]/[[softdb]]'));
7+
8+
foreach ([__DIR__ . '/../../../autoload.php', __DIR__ . '/../vendor/autoload.php'] as $file) {
9+
if (file_exists($file)) {
10+
require $file;
11+
break;
12+
}
13+
}
14+
15+
$input = fopen ("php://stdin","r");
16+
17+
echo " __ ____ \n / /______/ / /_ _ __\n / //_/ __ / __ \ | / /\n / ,< / /_/ / /_/ / |/ / \n/_/|_|\__,_/_.___/|___/ \n\n";
18+
echo "Usage:\n\tcommand [dsn] [arguments]\n\n";
19+
echo "Ex.:\n\tphp {$argv[0]} [DSN] [ARGUMENTS]\n\n";
20+
echo "DSN:\n\t<username>:<password>@<host>:<port>/<database>\n\n";
21+
echo "ARGUMENTS:\n\tmake\t\tcreates kdbv database";
22+
echo "\n\tupgrade\t\tupgrade database\n\n";
23+
24+
$_dsn = get_DSN($input);
25+
26+
if(empty($_dsn['prefix'])){
27+
$_dsn['prefix'] = '';
28+
}
29+
30+
while(count($_dsn) < 7){
31+
echo "\n\nALL FIELD ARE REQIRED\n\n";
32+
$_dsn = get_DSN($input);
33+
}
34+
35+
$obj = get_OBJ($_dsn);
36+
while(!get_ACTION($input,$obj)){}
37+
38+
fclose($input);
39+
40+
function get_DSN($input,$dsn = null){
41+
if($dsn == null){
42+
echo "ENTER DSN:";
43+
$dsn = fgets($input);
44+
$dsn = trim('mysql://'.$dsn);
45+
}
46+
$_dsn = parse_url($dsn);
47+
if(empty($_dsn['port'])){
48+
$_dsn['port'] = 3306;
49+
}
50+
$_dsn['path'] = trim($_dsn['path'],'/');
51+
$_dsn = get_prefix_kdbv($input,$_dsn);
52+
unset($_dsn['scheme']);
53+
return array_filter(array_map('trim',$_dsn));
54+
}
55+
56+
function get_ACTION($input,$obj){
57+
echo "ACTION:";
58+
$action = trim(fgets($input));
59+
switch($action){
60+
case 'make':
61+
$obj->make();
62+
echo "successfully kdbv database created";
63+
return true;
64+
break;
65+
case 'upgrade':
66+
$obj->upgrade();
67+
echo "Database upgraded successfully";
68+
return true;
69+
break;
70+
default :
71+
return false;
72+
}
73+
}
74+
75+
function get_OBJ($_dsn){
76+
return new kdbv(array(
77+
'HOST' => $_dsn['host'],
78+
'DATABASE' => $_dsn['path'],
79+
'USER' => $_dsn['user'],
80+
'PASS' => $_dsn['pass'],
81+
'PORT' => $_dsn['port'],
82+
'KDBV' => $_dsn['kdbv'], //name of kdbv database
83+
'PREFIX' => $_dsn['prefix'], //table prefix
84+
));
85+
}
86+
87+
function get_prefix_kdbv($input,$_dsn){
88+
echo "ENTER TABLE PREFIX:";
89+
$_dsn['prefix'] = fgets($input);
90+
echo "ENTER KDBV FILE LOCATION:";
91+
$_dsn['kdbv'] = fgets($input);
92+
return $_dsn;
93+
}

0 commit comments

Comments
 (0)