-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_afsh
98 lines (86 loc) · 2.62 KB
/
_afsh
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
#!/usr/bin/env php
<?php
require __DIR__.'/vendor/autoload.php';
define("MIGRATIONS_PATH", __DIR__."/database/migrations");
define("SEEDS_PATH", __DIR__."/database/seeds");
use \Slim\App;
require __DIR__.'/config/settings.php';
$app = new App($config);
require_once __DIR__.'/bootstrap/dependencies.php';
/**
* Script for creating, destroying, and seeding the app's database
*/
class Afsh {
function __construct($args,$container)
{
$this->args = $args;
$this->container = $container;
}
function help()
{
echo "\n";
echo "syntaxis: php afsh <command> [<args>]".PHP_EOL;
echo PHP_EOL;
echo "Commands: \n";
echo "php afsh --help --> Displays the help menu.".PHP_EOL;
echo "php afsh migrate --> Migrate the database.".PHP_EOL;
echo "php afsh seed --> Seed the database tables.".PHP_EOL;
echo "php afsh migrate --seed --> Migrate and seed the database.".PHP_EOL;
echo "php afsh serve --[port] --> php SERVER with port. localhost:8000 ".PHP_EOL;
echo PHP_EOL;
}
function runServer ()
{
if(isset($this->args[2])){
exec('php -S localhost:'.$this->args[2].'');
}else{
exec('php -S localhost:8000 ');
}
}
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 "serve":
$this->runServer();
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)
{
// echo " \n";
foreach ($files as $file) {
require_once($file);
$class = substr(basename($file, '.php'),1,strlen(basename($file, '.php')));
echo $class .' ++++ MIGRATION RUN ++++' .PHP_EOL;
$obj = new $class($this->container);
$obj->run();
}
}
}
$afsh = new Afsh($argv,$container);
$afsh->exec();