Init
This commit is contained in:
0
core/app/Console/Commands/.gitkeep
Normal file
0
core/app/Console/Commands/.gitkeep
Normal file
71
core/app/Console/Commands/HRCCommand.php
Normal file
71
core/app/Console/Commands/HRCCommand.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* Class HRCCommand
|
||||
*
|
||||
* @property object data
|
||||
*/
|
||||
class HRCCommand extends Command
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->signature = $this->signature . ' {source} {result} {--unn=}';
|
||||
parent::__construct();
|
||||
|
||||
print_r($this->getApplication());
|
||||
}
|
||||
|
||||
public function __get($get)
|
||||
{
|
||||
if ($get == 'data') {
|
||||
return $this->prepareRaw();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private function prepareRaw()
|
||||
{
|
||||
$source_file = base_path() . '/../temp/' . $this->argument('source');
|
||||
return json_decode(file_get_contents($source_file));
|
||||
}
|
||||
|
||||
public function save($result)
|
||||
{
|
||||
$result_file = base_path() . '/../temp/' . $this->argument('result');
|
||||
file_put_contents($result_file, json_encode($result));
|
||||
}
|
||||
|
||||
public function initDB()
|
||||
{
|
||||
$code = $this->option('unn');
|
||||
|
||||
DB::disconnect('mysql');
|
||||
Config::set('database.connections.mysql.database', $code);
|
||||
DB::reconnect();
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$data = $this->prepareRaw();
|
||||
$this->initDB();
|
||||
|
||||
try {
|
||||
$result = $this->command($data);
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$result = [
|
||||
'status' => 'error',
|
||||
'message' => $e->getMessage()
|
||||
];
|
||||
}
|
||||
|
||||
$this->save($result);
|
||||
}
|
||||
}
|
||||
7
core/app/Console/Commands/HRCCommandInterface.php
Normal file
7
core/app/Console/Commands/HRCCommandInterface.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
interface HRCCommandInterface {
|
||||
public function command($data);
|
||||
}
|
||||
30
core/app/Console/Kernel.php
Normal file
30
core/app/Console/Kernel.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use App\Commands\HelloWorld;
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Laravel\Lumen\Console\Kernel as ConsoleKernel;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
/**
|
||||
* The Artisan commands provided by your application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $commands = [
|
||||
HelloWorld::class
|
||||
];
|
||||
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
* @return void
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user