Add migrations and seeders support
This commit is contained in:
@@ -17,8 +17,6 @@ class HRCCommand extends Command
|
||||
{
|
||||
$this->signature = $this->signature . ' {source} {result} {--unn=}';
|
||||
parent::__construct();
|
||||
|
||||
print_r($this->getApplication());
|
||||
}
|
||||
|
||||
public function __get($get)
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
class ExampleEvent extends Event
|
||||
{
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
43
core/app/Helpers/ClassHelper.php
Normal file
43
core/app/Helpers/ClassHelper.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
class ClassHelper
|
||||
{
|
||||
public static function extract($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;
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
class ExampleController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
//
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
|
||||
class ExampleMiddleware
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
class ExampleJob extends Job
|
||||
{
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Events\ExampleEvent;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
|
||||
class ExampleListener
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param \App\Events\ExampleEvent $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(ExampleEvent $event)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
@@ -15,4 +16,15 @@ class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function boot()
|
||||
{
|
||||
$migrations_path = base_path() . '/../database/migrations';
|
||||
$default_path = database_path('migrations');
|
||||
|
||||
$this->loadMigrationsFrom([
|
||||
$default_path,
|
||||
$migrations_path
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user