Archived
1
0
Fork 0

Initial Commit

This commit is contained in:
Henrik Hautakoski 2020-10-03 16:07:18 +02:00
commit 9b22323711
36 changed files with 7164 additions and 0 deletions

View file

View file

@ -0,0 +1,36 @@
<?php
namespace App\Console\Commands;
use App\Models\Word;
use Illuminate\Console\Command;
class AddWordCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'addword {word} {type}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Add a word to the database';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$row = new Word;
$row->value = $this->argument('word');
$row->type = $this->argument('type');
$row->save();
}
}

29
app/Console/Kernel.php Normal file
View file

@ -0,0 +1,29 @@
<?php
namespace App\Console;
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\AddWordCommand::class
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
//
}
}

View file

@ -0,0 +1,59 @@
<?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 Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
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)
{
if (env('APP_DEBUG') == false && $exception instanceof NotFoundHttpException) {
return response(view("errors.404"), 404);
}
return parent::render($request, $exception);
}
}

52
app/Models/Word.php Normal file
View file

@ -0,0 +1,52 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Word extends Model
{
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;
/**
* Get the route key for the model.
*
* @return string
*/
public function getRouteKeyName()
{
return 'uuid';
}
static public function boot()
{
static::saving(function($model) {
$model->uuid = substr(base64_encode($model->value), 0, 10);
});
parent::boot();
}
/**
* Return a random row from the table.
*
* @var mixed $exclude uuid's of rows that should be excluded.
*/
static public function getRandom($exclude = [])
{
$q = self::inRandomOrder();
if (!is_array($exclude)) {
$exclude = [ $exclude ];
}
if (count($exclude) > 1) {
$q->where("uuid", 'NOT IN', $exclude);
}
return $q->first();
}
}

View file

@ -0,0 +1,29 @@
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
//
}
}

22
app/View/Helpers.php Normal file
View file

@ -0,0 +1,22 @@
<?php
if (!function_exists('urlGenerator')) {
/**
* @return \Laravel\Lumen\Routing\UrlGenerator
*/
function urlGenerator() {
return new \Laravel\Lumen\Routing\UrlGenerator(app());
}
}
if (!function_exists('asset')) {
/**
* @param $path
* @param bool $secured
*
* @return string
*/
function asset($path, $secured = false) {
return urlGenerator()->asset($path, $secured);
}
}