Skeleton is ready
This commit is contained in:
11
app/Kernel/DateTime/Format.php
Normal file
11
app/Kernel/DateTime/Format.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Kernel\DateTime;
|
||||
|
||||
enum Format: string
|
||||
{
|
||||
case CutISO8601DateTime = 'Y-m-d H:i:s';
|
||||
case CutISO8601Date = 'Y-m-d';
|
||||
}
|
||||
17
app/Kernel/DateTime/Util.php
Normal file
17
app/Kernel/DateTime/Util.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Kernel\DateTime;
|
||||
|
||||
use DateTimeInterface;
|
||||
|
||||
class Util
|
||||
{
|
||||
public static function toString(
|
||||
DateTimeInterface $datetime,
|
||||
Format $format
|
||||
): string{
|
||||
return $datetime->format($format->value);
|
||||
}
|
||||
}
|
||||
12
app/Kernel/Db/Ilike.php
Normal file
12
app/Kernel/Db/Ilike.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Kernel\Db;
|
||||
|
||||
enum Ilike: string
|
||||
{
|
||||
case StartsWith = '%s%%%%';
|
||||
case EndsWith = '%%%s';
|
||||
case Contains = '%%%%%s%%%%';
|
||||
}
|
||||
16
app/Kernel/Db/Query.php
Normal file
16
app/Kernel/Db/Query.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Kernel\Db;
|
||||
|
||||
class Query
|
||||
{
|
||||
public static function ilike(
|
||||
int|float|string $value,
|
||||
string $modifier = '%s',
|
||||
Ilike $mode = Ilike::Contains
|
||||
): string {
|
||||
return sprintf(sprintf($mode->value, $modifier), $value);
|
||||
}
|
||||
}
|
||||
9
app/Kernel/Event/Event.php
Normal file
9
app/Kernel/Event/Event.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Kernel\Event;
|
||||
|
||||
enum Event: string
|
||||
{
|
||||
}
|
||||
15
app/Kernel/Feature/HasCommandsList.php
Normal file
15
app/Kernel/Feature/HasCommandsList.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Kernel\Feature;
|
||||
|
||||
trait HasCommandsList
|
||||
{
|
||||
public function registerCommands(): void
|
||||
{
|
||||
if (isset($this->commandsList) && method_exists($this, 'commands')) {
|
||||
$this->commands($this->commandsList);
|
||||
}
|
||||
}
|
||||
}
|
||||
25
app/Kernel/Feature/HasEventListeners.php
Normal file
25
app/Kernel/Feature/HasEventListeners.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Kernel\Feature;
|
||||
|
||||
use Illuminate\Support\Facades\Event;
|
||||
|
||||
trait HasEventListeners
|
||||
{
|
||||
public function registerListeners(): void
|
||||
{
|
||||
if (isset($this->eventListeners)) {
|
||||
/**
|
||||
* @var string $event
|
||||
* @var array<int,string> $listeners
|
||||
*/
|
||||
foreach ($this->eventListeners as $event => $listeners) {
|
||||
foreach ($listeners as $listener) {
|
||||
Event::listen($event, $listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
10
app/Kernel/Http/ContentType.php
Normal file
10
app/Kernel/Http/ContentType.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Kernel\Http;
|
||||
|
||||
enum ContentType: string
|
||||
{
|
||||
case ApplicationJson = 'application/json';
|
||||
}
|
||||
10
app/Kernel/Http/Header.php
Normal file
10
app/Kernel/Http/Header.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Kernel\Http;
|
||||
|
||||
enum Header: string
|
||||
{
|
||||
case Accept = 'Accept';
|
||||
}
|
||||
39
app/Kernel/Http/Middleware/CheckAcceptHeader.php
Normal file
39
app/Kernel/Http/Middleware/CheckAcceptHeader.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Kernel\Http\Middleware;
|
||||
|
||||
use App\Kernel\Http\ContentType;
|
||||
use App\Kernel\Http\Header;
|
||||
use App\Kernel\Object\Enum;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException;
|
||||
|
||||
class CheckAcceptHeader
|
||||
{
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
$headerFound = false;
|
||||
|
||||
if ($this->acceptApplicationJson($request)) {
|
||||
$headerFound = true;
|
||||
}
|
||||
|
||||
if ($request->isMethod('OPTIONS') || $headerFound) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
throw new NotAcceptableHttpException('Valid accept header not found');
|
||||
}
|
||||
|
||||
private function acceptApplicationJson(Request $request): bool
|
||||
{
|
||||
$passedHeader = $request->headers->get(Header::Accept->value);
|
||||
$expectedHeader = Enum::value(ContentType::ApplicationJson);
|
||||
|
||||
return $passedHeader === $expectedHeader;
|
||||
}
|
||||
}
|
||||
15
app/Kernel/Http/Validation.php
Normal file
15
app/Kernel/Http/Validation.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Kernel\Http;
|
||||
|
||||
use App\Kernel\String\Regex;
|
||||
|
||||
class Validation
|
||||
{
|
||||
public static function uuid7(): string
|
||||
{
|
||||
return sprintf('regex:/%s/', Regex::Uuid7->value);
|
||||
}
|
||||
}
|
||||
27
app/Kernel/Object/Enum.php
Normal file
27
app/Kernel/Object/Enum.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Kernel\Object;
|
||||
|
||||
use BackedEnum;
|
||||
|
||||
class Enum
|
||||
{
|
||||
/**
|
||||
* Extract values from an array of BackedEnum instances.
|
||||
*
|
||||
* @param array<int,BackedEnum> $enums
|
||||
*
|
||||
* @return array<int,int|string|float>
|
||||
*/
|
||||
public static function values(array $enums): array
|
||||
{
|
||||
return array_map(fn (BackedEnum $enum) => static::value($enum), $enums);
|
||||
}
|
||||
|
||||
public static function value(BackedEnum $enum): int|string|float
|
||||
{
|
||||
return $enum->value;
|
||||
}
|
||||
}
|
||||
17
app/Kernel/Object/HasHiddenAttributes.php
Normal file
17
app/Kernel/Object/HasHiddenAttributes.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Kernel\Object;
|
||||
|
||||
trait HasHiddenAttributes
|
||||
{
|
||||
public function isHidden(string $key): bool
|
||||
{
|
||||
if (property_exists($this, 'hidden') && is_array($this->hidden)) {
|
||||
return in_array($key, $this->hidden, true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
10
app/Kernel/Object/HasPermissions.php
Normal file
10
app/Kernel/Object/HasPermissions.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Kernel\Object;
|
||||
|
||||
interface HasPermissions
|
||||
{
|
||||
public function permissions(): array;
|
||||
}
|
||||
10
app/Kernel/Object/HasRoles.php
Normal file
10
app/Kernel/Object/HasRoles.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Kernel\Object;
|
||||
|
||||
interface HasRoles
|
||||
{
|
||||
public function roles(): array;
|
||||
}
|
||||
7
app/Kernel/Object/HasRolesWithPermissions.php
Normal file
7
app/Kernel/Object/HasRolesWithPermissions.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Kernel\Object;
|
||||
|
||||
interface HasRolesWithPermissions extends HasRoles, HasPermissions {}
|
||||
10
app/Kernel/Object/HasUuidAsIdentifier.php
Normal file
10
app/Kernel/Object/HasUuidAsIdentifier.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Kernel\Object;
|
||||
|
||||
interface HasUuidAsIdentifier
|
||||
{
|
||||
public function id(): string;
|
||||
}
|
||||
9
app/Kernel/Queue/Queue.php
Normal file
9
app/Kernel/Queue/Queue.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Kernel\Queue;
|
||||
|
||||
enum Queue: string
|
||||
{
|
||||
}
|
||||
11
app/Kernel/Role/Role.php
Normal file
11
app/Kernel/Role/Role.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Kernel\Role;
|
||||
|
||||
enum Role: string
|
||||
{
|
||||
case Admin = 'admin';
|
||||
case User = 'user';
|
||||
}
|
||||
13
app/Kernel/String/Hash.php
Normal file
13
app/Kernel/String/Hash.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Kernel\String;
|
||||
|
||||
class Hash
|
||||
{
|
||||
public static function xxh128(string $value): string
|
||||
{
|
||||
return hash('xxh128', $value);
|
||||
}
|
||||
}
|
||||
11
app/Kernel/String/Regex.php
Normal file
11
app/Kernel/String/Regex.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Kernel\String;
|
||||
|
||||
enum Regex: string
|
||||
{
|
||||
case Uuid7 = '^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$';
|
||||
case Numeric = '^[0-9]+$';
|
||||
}
|
||||
10
app/Kernel/String/String.php
Normal file
10
app/Kernel/String/String.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Kernel\String;
|
||||
|
||||
enum String: string
|
||||
{
|
||||
case Empty = '';
|
||||
}
|
||||
Reference in New Issue
Block a user