Add migrations and seeders support

This commit is contained in:
2021-01-14 14:16:52 +03:00
parent d12744296a
commit cb1f3a6bb5
15 changed files with 196 additions and 311 deletions

View File

@@ -5,6 +5,7 @@ namespace App\Console;
use App\Commands\HelloWorld;
use Illuminate\Console\Scheduling\Schedule;
use Laravel\Lumen\Console\Kernel as ConsoleKernel;
use App\Helpers\ClassHelper;
class Kernel extends ConsoleKernel
{
@@ -19,51 +20,14 @@ class Kernel extends ConsoleKernel
//
}
private function extractClass($file)
{
$fp = fopen($file, 'r');
$class = $namespace = $buffer = '';
$i = 0;
while (!$class) {
if (feof($fp)) break;
$buffer .= fread($fp, 512);
$tokens = token_get_all($buffer);
if (strpos($buffer, '{') === false) continue;
for (;$i<count($tokens);$i++) {
if ($tokens[$i][0] === T_NAMESPACE) {
for ($j=$i+1;$j<count($tokens); $j++) {
if ($tokens[$j][0] === T_STRING) {
$namespace .= '\\'.$tokens[$j][1];
} else if ($tokens[$j] === '{' || $tokens[$j] === ';') {
break;
}
}
}
if ($tokens[$i][0] === T_CLASS) {
for ($j=$i+1;$j<count($tokens);$j++) {
if ($tokens[$j] === '{') {
$class = $tokens[$i+2][1];
}
}
}
}
}
return $namespace . '\\' . $class;
}
public function getCommands()
{
$commands_path = base_path() . '/../commands';
$files = array_diff(scandir(base_path() . '/../commands'), array('.', '..'));
$files = array_diff(scandir($commands_path), array('.', '..'));
$classes = [];
foreach($files as $file) {
$classes[] = $this->extractClass($commands_path . '/' . $file);
$classes[] = ClassHelper::extract($commands_path . '/' . $file);
}
$commands = parent::getCommands();