Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lumen to Laravel Converter #36

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions .unshifted-lumen-files/app/Console/Kernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace App\Console;

use App\Jobs\DailySummary;
use App\Jobs\HandleANEPCImportantData;
use App\Jobs\HandleANEPCPositEmail;
use App\Jobs\HourlySummary;
use App\Jobs\ProcessANPCAllDataV2;
use App\Jobs\ProcessDataForHistoryTotal;
use App\Jobs\ProcessMadeiraWarnings;
use App\Jobs\ProcessPlanes;
use App\Jobs\ProcessRCM;
use App\Jobs\UpdateICNFData;
use App\Jobs\UpdateWeatherData;
use App\Jobs\UpdateWeatherDataDaily;
use App\Jobs\UpdateWeatherStations;
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 = [
\App\Console\Commands\TestStuff::class,
\App\Console\Commands\FixKMLData::class,
\App\Console\Commands\FixFMA::class,
\App\Console\Commands\SaveWarningAndSendNotificationAndSocial::class,
\App\Console\Commands\GetICNFBurnAreaLegacy::class,
\App\Console\Commands\ImportLocations::class,
];

/**
* Define the application's command schedule.
*/
protected function schedule(Schedule $schedule)
{
if (env('SCHEDULER_ENABLE')) {
$schedule->job(new HourlySummary())->hourlyAt(0);
$schedule->job(new ProcessANPCAllDataV2())->everyTwoMinutes();
$schedule->job(new ProcessDataForHistoryTotal())->everyTwoMinutes();
//$schedule->job(new ProcessMadeiraWarnings())->everyTenMinutes();
//$schedule->job(new ProcessPlanes())->everyFiveMinutes();
$schedule->job(new ProcessRCM(true))->daily()->at('09:00');
$schedule->job(new ProcessRCM(false))->hourly(); // update RCM
$schedule->job(new ProcessRCM(true, true))->daily()->at('18:00');

$schedule->job(new UpdateICNFData(0))->everyFourHours();
$schedule->job(new UpdateICNFData(1))->twiceDaily();
$schedule->job(new UpdateICNFData(2))->dailyAt('06:00');
$schedule->job(new UpdateICNFData(3))->cron('0 2 */2 * *'); // every 2 days
$schedule->job(new UpdateICNFData(4))->cron('0 3 * * 1,5'); // twice a week, monday and thursday
$schedule->job(new UpdateICNFData(5))->cron('0 3 * * 1,5'); // twice a week, monday and thursday
$schedule->job(new UpdateICNFData(6))->cron('0 3 * * 3'); // once a week, wednesday

$schedule->job(new UpdateWeatherStations())->daily()->at('03:21');
$schedule->job(new UpdateWeatherData())->everyTwoHours();

$schedule->job(new UpdateWeatherDataDaily())->daily()->at('04:21');

$schedule->job(new DailySummary())->daily()->at('09:30');

//$schedule->job(new HandleANEPCImportantData())->everyTenMinutes();
//$schedule->job(new HandleANEPCPositEmail())->everyTenMinutes();
}
}
}
58 changes: 58 additions & 0 deletions .unshifted-lumen-files/app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?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.
*
* @throws \Exception
*/
public function report(Throwable $exception)
{
parent::report($exception);
}

/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Response
*
* @throws \Throwable
*/
public function render($request, Throwable $exception)
{
if (app()->bound('sentry') && $this->shouldReport($exception)) {
app('sentry')->captureException($exception);
}

if ($exception instanceof ModelNotFoundException && $request->wantsJson()) {
return response()->json(['message' => 'Not Found!'], 404);
}

return parent::render($request, $exception);
}
}
40 changes: 40 additions & 0 deletions .unshifted-lumen-files/app/Http/Middleware/Authenticate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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.
*/
public function __construct(Auth $auth)
{
$this->auth = $auth;
}

/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param null|string $guard
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
{
if ($this->auth->guard($guard)->guest()) {
return response('Unauthorized.', 401);
}

return $next($request);
}
}
35 changes: 35 additions & 0 deletions .unshifted-lumen-files/app/Models/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Models;

use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Laravel\Lumen\Auth\Authorizable;

class User extends Model implements AuthenticatableContract, AuthorizableContract
{
use Authenticatable;
use Authorizable;
use HasFactory;

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email',
];

/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = [
'password',
];
}
16 changes: 16 additions & 0 deletions .unshifted-lumen-files/app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Providers;

use Illuminate\Support\Facades\URL;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
public function boot(): void
{
if (app()->environment('production')) {
URL::forceScheme('https');
}
}
}
28 changes: 28 additions & 0 deletions .unshifted-lumen-files/app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Providers;

use App\Models\User;
use Illuminate\Support\ServiceProvider;

class AuthServiceProvider extends ServiceProvider
{
/**
* Boot the authentication services for the application.
*/
public function boot(): void
{
// 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();
}

return null;
});
}
}
15 changes: 15 additions & 0 deletions .unshifted-lumen-files/app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?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 = [];
}
116 changes: 116 additions & 0 deletions .unshifted-lumen-files/bootstrap/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php

use Laravel\Lumen\Routing\Router;

require_once __DIR__.'/../vendor/autoload.php';

(new Laravel\Lumen\Bootstrap\LoadEnvironmentVariables(
dirname(__DIR__)
))->bootstrap();

date_default_timezone_set(env('APP_TIMEZONE', 'UTC'));

/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| Here we will load the environment and create the application instance
| that serves as the central piece of this framework. We'll use this
| application as an "IoC" container and router for this framework.
|
*/

$app = new Laravel\Lumen\Application(
dirname(__DIR__)
);

/*
|--------------------------------------------------------------------------
| Register Container Bindings
|--------------------------------------------------------------------------
|
| Now we will register a few bindings in the service container. We will
| register the exception handler and the console kernel. You may add
| your own bindings here if you like or you can make another file.
|
*/

$app->singleton(
Illuminate\Contracts\Debug\ExceptionHandler::class,
App\Exceptions\Handler::class
);

$app->singleton(
Illuminate\Contracts\Console\Kernel::class,
App\Console\Kernel::class
);

/*
|--------------------------------------------------------------------------
| Register Config Files
|--------------------------------------------------------------------------
|
| Now we will register the "app" configuration file. If the file exists in
| your configuration directory it will be loaded; otherwise, we'll load
| the default version. You may register other files below as needed.
|
*/
$app->configure('app');

/*
|--------------------------------------------------------------------------
| Register Middleware
|--------------------------------------------------------------------------
|
| Next, we will register the middleware with the application. These can
| be global middleware that run before and after each request into a
| route or middleware that'll be assigned to some specific routes.
|
*/

// $app->middleware([
// App\Http\Middleware\ExampleMiddleware::class
// ]);

// $app->routeMiddleware([
// 'auth' => App\Http\Middleware\Authenticate::class,
// ]);

/*
|--------------------------------------------------------------------------
| Register Service Providers
|--------------------------------------------------------------------------
|
| Here we will register all of the application's service providers which
| are used to bind services into the container. Service providers are
| totally optional, so you are not required to uncomment this line.
|
*/

$app->register(App\Providers\AppServiceProvider::class);
// $app->register(App\Providers\AuthServiceProvider::class);
// $app->register(App\Providers\EventServiceProvider::class);
$app->register(Jenssegers\Mongodb\MongodbServiceProvider::class);
$app->register(Flipbox\LumenGenerator\LumenGeneratorServiceProvider::class);
$app->register(Illuminate\Redis\RedisServiceProvider::class);
$app->register(Sentry\Laravel\ServiceProvider::class);
$app->register(Anik\Form\FormRequestServiceProvider::class);

$app->withFacades();
$app->withEloquent();

/*
|--------------------------------------------------------------------------
| Load The Application Routes
|--------------------------------------------------------------------------
|
| Next we will include the routes file so that they can all be added to
| the application. This will provide all of the URLs the application
| can respond to, as well as the controllers that may handle them.
|
*/

$app->router->group([], static fn (Router $router) => require __DIR__.'/../routes/web.php');

return $app;
Loading
Loading