-
Notifications
You must be signed in to change notification settings - Fork 0
/
novice
82 lines (67 loc) · 1.94 KB
/
novice
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
#!/usr/bin/env php
<?php
require __DIR__.'/vendor/autoload.php';
define("MIGRATIONS_PATH", __DIR__."/app/database/migrations");
define("SEEDS_PATH", __DIR__."/app/database/seeds");
/**
* Script for creating, destroying, and seeding the app's database
*/
class Novice {
function __construct($args)
{
$this->args = $args;
}
function help()
{
echo "\n";
echo "syntaxis: php novice <command> [<args>]".PHP_EOL;
echo PHP_EOL;
echo "Commands: \n";
echo "php novice --help --> Displays the help menu.".PHP_EOL;
echo "php novice migrate --> Migrate the database.".PHP_EOL;
echo "php novice seed --> Seed the database tables.".PHP_EOL;
echo "php novice novice migrate --seed --> Migrate and seed the database.".PHP_EOL;
echo PHP_EOL;
}
function exec()
{
if (count($this->args) <= 1) {
$this->help();
} else {
switch ($this->args[1]) {
case "migrate":
$this->runMigrations();
if (!isset($this->args[2]) || $this->args[2] != '--seed')
break;
case "seed":
$this->runSeed();
break;
case "help":
case "--help":
$this->help();
break;
}
}
}
function runMigrations()
{
$files = glob(MIGRATIONS_PATH.'/*.php');
$this->run($files);
}
function runSeed()
{
$files = glob(SEEDS_PATH.'/*.php');
$this->run($files);
}
private function run($files)
{
foreach ($files as $file) {
require_once($file);
$class = basename($file, '.php');
$obj = new $class;
$obj->run();
}
}
}
$novice = new Novice($argv);
$novice->exec();