-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.php
66 lines (59 loc) · 2.04 KB
/
index.php
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
<?php
$start = microtime();
require __DIR__ . '/vendor/autoload.php';
use App\DbToModel;
use App\setup\Inflector;
$obj = new DbToModel("localhost", "root", "", "testdb");
$result = $obj->getDatabaseTables();
if (count($result) > 0)
{
if (is_dir(__DIR__."models"))
{
$dir = 'models';
$it = new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS);
$files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
foreach($files as $file) {
if ($file->isDir()) {
rmdir($file->getRealPath());
} else {
unlink($file->getRealPath());
}
}
rmdir(__DIR__.$dir);
}
mkdir("models", 0777, true);
foreach ($result as $r)
{
foreach($r as $o => $v)
{
$columns = $obj->getColumnsInTable($v);
if (count($columns) > 0)
{
// create the model file
$laravelModelName = Inflector::singularize(str_replace(" ", "", ucwords(str_replace("_", " ", $v))));
// create the file content
$modelFileContent = $obj->writeFileOpeningProperties($laravelModelName, $v);
foreach($columns as $c => $v)
{
$modelFileContent .= "\t\t'" . $v['Field'] . "', \n";
}
$modelFileContent .= $obj->writeFileClosingProperties();
// write the file content to folder models.
if (file_put_contents("models/$laravelModelName.php", $modelFileContent) !== false)
{
echo "Model: $laravelModelName was successfully created.\n";
}
else
{
echo "Unable to create model: $laravelModelName.\n";
}
}
}
}
}
else
{
echo "Seems like this is a new database with no tables :)";
}
echo "Done. Program ran successfully in " . ($start - microtime()) . "milliseconds.";
exit;