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);
|
||||
}
|
||||
}
|
||||
10
app/Events/Event.php
Normal file
10
app/Events/Event.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
abstract class Event
|
||||
{
|
||||
use SerializesModels;
|
||||
}
|
||||
54
app/Exceptions/Handler.php
Normal file
54
app/Exceptions/Handler.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Throwable;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
/**
|
||||
* A list of the exception types that should not be reported.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dontReport = [
|
||||
AuthorizationException::class,
|
||||
HttpException::class,
|
||||
ModelNotFoundException::class,
|
||||
ValidationException::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Report or log an exception.
|
||||
*
|
||||
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
|
||||
*
|
||||
* @param \Throwable $exception
|
||||
* @return void
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function report(Throwable $exception)
|
||||
{
|
||||
parent::report($exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an exception into an HTTP response.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Throwable $exception
|
||||
* @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function render($request, Throwable $exception)
|
||||
{
|
||||
return parent::render($request, $exception);
|
||||
}
|
||||
}
|
||||
43
app/Helpers/ClassHelper.php
Normal file
43
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;
|
||||
}
|
||||
}
|
||||
10
app/Http/Controllers/Controller.php
Normal file
10
app/Http/Controllers/Controller.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Laravel\Lumen\Routing\Controller as BaseController;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
//
|
||||
}
|
||||
44
app/Http/Middleware/Authenticate.php
Normal file
44
app/Http/Middleware/Authenticate.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Auth\Factory as Auth;
|
||||
|
||||
class Authenticate
|
||||
{
|
||||
/**
|
||||
* The authentication guard factory instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Auth\Factory
|
||||
*/
|
||||
protected $auth;
|
||||
|
||||
/**
|
||||
* Create a new middleware instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Auth\Factory $auth
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Auth $auth)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next, $guard = null)
|
||||
{
|
||||
if ($this->auth->guard($guard)->guest()) {
|
||||
return response('Unauthorized.', 401);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
24
app/Jobs/Job.php
Normal file
24
app/Jobs/Job.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
abstract class Job implements ShouldQueue
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Queueable Jobs
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This job base class provides a central location to place any logic that
|
||||
| is shared across all of your jobs. The trait included with the class
|
||||
| provides access to the "queueOn" and "delay" queue helper methods.
|
||||
|
|
||||
*/
|
||||
|
||||
use InteractsWithQueue, Queueable, SerializesModels;
|
||||
}
|
||||
20
app/Models/Right.php
Normal file
20
app/Models/Right.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Right extends Model {
|
||||
protected $table = 'rights';
|
||||
|
||||
public static function add($code, $name)
|
||||
{
|
||||
if(Right::where('code', $code)->count() == 0) {
|
||||
$right = new Right([
|
||||
'code' => $code,
|
||||
'name' => $name
|
||||
]);
|
||||
$right->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
30
app/Models/Subscriber.php
Normal file
30
app/Models/Subscriber.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Subscriber extends Model
|
||||
{
|
||||
protected $table = 'subscribers';
|
||||
|
||||
public static function add($event, $callback, $weight = 0)
|
||||
{
|
||||
list($destination_module, $destination_method) = explode(':', $callback);
|
||||
list($source_module, $source_method) = explode(':', $event);
|
||||
|
||||
$code = strtolower($destination_module . '_' . $destination_method . '_after_' . $source_module . '_' . $source_method);
|
||||
|
||||
if (Subscriber::where('code', $code)->count() == 0) {
|
||||
$subscriber = new Subscriber([
|
||||
'code' => $code,
|
||||
'destination_module' => strtolower($destination_module),
|
||||
'destination_method' => strtolower($destination_method),
|
||||
'source_module' => strtolower($source_module),
|
||||
'source_method' => strtolower($source_method),
|
||||
'weight' => $weight
|
||||
]);
|
||||
$subscriber->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
9
app/Models/User.php
Normal file
9
app/Models/User.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class User extends Model {
|
||||
protected $table = 'users';
|
||||
}
|
||||
30
app/Providers/AppServiceProvider.php
Normal file
30
app/Providers/AppServiceProvider.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function boot()
|
||||
{
|
||||
$migrations_path = base_path() . '/../database/migrations';
|
||||
$default_path = database_path('migrations');
|
||||
|
||||
$this->loadMigrationsFrom([
|
||||
$default_path,
|
||||
$migrations_path
|
||||
]);
|
||||
}
|
||||
}
|
||||
39
app/Providers/AuthServiceProvider.php
Normal file
39
app/Providers/AuthServiceProvider.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AuthServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Boot the authentication services for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
// Here you may define how you wish users to be authenticated for your Lumen
|
||||
// application. The callback which receives the incoming request instance
|
||||
// should return either a User instance or null. You're free to obtain
|
||||
// the User instance via an API token or any other method necessary.
|
||||
|
||||
$this->app['auth']->viaRequest('api', function ($request) {
|
||||
if ($request->input('api_token')) {
|
||||
return User::where('api_token', $request->input('api_token'))->first();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
19
app/Providers/EventServiceProvider.php
Normal file
19
app/Providers/EventServiceProvider.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Laravel\Lumen\Providers\EventServiceProvider as ServiceProvider;
|
||||
|
||||
class EventServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The event listener mappings for the application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $listen = [
|
||||
\App\Events\ExampleEvent::class => [
|
||||
\App\Listeners\ExampleListener::class,
|
||||
],
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user