Version 1.0
This commit is contained in:
0
app/Console/Commands/.gitkeep
Normal file
0
app/Console/Commands/.gitkeep
Normal file
88
app/Console/Commands/HRCCommand.php
Normal file
88
app/Console/Commands/HRCCommand.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?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();
|
||||
}
|
||||
|
||||
public function __get($get)
|
||||
{
|
||||
if ($get == 'data') {
|
||||
return $this->prepareRaw();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private function prepareInput()
|
||||
{
|
||||
$source_file = base_path() . '/../temp/' . $this->argument('source');
|
||||
$data = parse_ini_file($source_file);
|
||||
|
||||
if(isset($data['raw_result'])) {
|
||||
unset($data['raw_result']);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function prepareOutput()
|
||||
{
|
||||
$source_file = base_path() . '/../temp/' . $this->argument('source');
|
||||
$data = parse_ini_file($source_file);
|
||||
|
||||
if(isset($data['raw_result'])) {
|
||||
return json_decode(base64_decode($data['raw_result']), true);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
$input = $this->prepareInput();
|
||||
$output = $this->prepareOutput();
|
||||
|
||||
try {
|
||||
$this->initDB();
|
||||
$result = $this->command($input, $output);
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$result = [
|
||||
'status' => 'error',
|
||||
'message' => $e->getMessage()
|
||||
];
|
||||
}
|
||||
|
||||
$this->save($result);
|
||||
}
|
||||
}
|
||||
7
app/Console/Commands/HRCCommandInterface.php
Normal file
7
app/Console/Commands/HRCCommandInterface.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
interface HRCCommandInterface {
|
||||
public function command($input, $output = null);
|
||||
}
|
||||
36
app/Console/Kernel.php
Normal file
36
app/Console/Kernel.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
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
|
||||
{
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
* @return void
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function getCommands()
|
||||
{
|
||||
$commands_path = base_path() . '/../commands';
|
||||
$files = array_diff(scandir($commands_path), array('.', '..'));
|
||||
|
||||
$classes = [];
|
||||
foreach($files as $file) {
|
||||
$classes[] = ClassHelper::extract($commands_path . '/' . $file);
|
||||
}
|
||||
|
||||
$commands = parent::getCommands();
|
||||
return array_merge($commands, $classes);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user