-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsilla
executable file
·85 lines (69 loc) · 2.46 KB
/
silla
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
#!/usr/bin/env php
<?php
/**
* Silla.IO CLI Task Manager.
*
* @package Silla.IO
* @subpackage Core
* @author Kalin Stefanov <[email protected]>
* @copyright Copyright (c) 2015, Silla.io
* @license http://opensource.org/licenses/GPL-3.0 GNU General Public License, version 3.0 (GPLv3)
*/
namespace Core;
use Core\CLI;
$mode = 'app';
/* Get environment from the CLI parameters */
foreach ($argv as $key => $parameter) {
if (strpos($parameter, '--environment') === 0) {
$environment = str_replace('--environment=', '', $parameter);
unset($argv[$key]);
} else if (strpos($parameter, '--mode') === 0) {
$mode = str_replace('--mode=', '', $parameter);
unset($argv[$key]);
}
}
if (isset($environment)) {
putenv("ENV_SILLA_ENVIRONMENT=$environment");
}
require_once __DIR__ . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'loader.php';
require_once __DIR__ . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'boot.php';
Config()->setMode(Config()->modes($mode));
if ($argc > 1) {
$argv = array_values($argv);
$parts = explode(':', $argv[1]);
$command = implode(':', array_slice($parts, 1));
$class = 'Core\CLI\\' . $parts[0];
if ('db' === $command) {
$migrations = array_map(function ($item) {
$name = substr($item, 0, -4);
return array(
'name' => $name,
'version' => substr($name, -10),
);
}, array_slice(
scandir(Config()->paths('root') . 'db' . DIRECTORY_SEPARATOR . 'migrations' . DIRECTORY_SEPARATOR),
2
));
usort($migrations, function ($a, $b) {
return $a['version'] < $b['version'];
});
CLI\DB::$migrations = $migrations;
} elseif ('generate' === $command) {
call_user_func_array(array($class, $command), array_slice($argv, 2));
} else {
if (!class_exists($class)) {
$class = 'Core\CLI\\' . implode('\\', $parts);
}
if (!class_exists($class)) {
$class = '\\' . implode('\\', $parts);
}
try {
if (method_exists($class, 'init')) {
call_user_func_array(array($class, 'init'), array(array_slice($argv, 2)));
}
call_user_func_array(array($class, 'run'), array(array_slice($argv, 2)));
} catch (\Exception $e) {
exit('[' . get_class($e) . '] ' . $e->getMessage() . PHP_EOL);
}
}
}