Skeleton is ready

This commit is contained in:
2026-01-05 16:33:20 +04:00
commit eeaf43ab5d
89 changed files with 2704 additions and 0 deletions

View 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';
}

View 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
View 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
View 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);
}
}

View File

@@ -0,0 +1,9 @@
<?php
declare(strict_types=1);
namespace App\Kernel\Event;
enum Event: string
{
}

View 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);
}
}
}

View 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);
}
}
}
}
}

View File

@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace App\Kernel\Http;
enum ContentType: string
{
case ApplicationJson = 'application/json';
}

View File

@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace App\Kernel\Http;
enum Header: string
{
case Accept = 'Accept';
}

View 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;
}
}

View 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);
}
}

View 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;
}
}

View 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;
}
}

View File

@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace App\Kernel\Object;
interface HasPermissions
{
public function permissions(): array;
}

View File

@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace App\Kernel\Object;
interface HasRoles
{
public function roles(): array;
}

View File

@@ -0,0 +1,7 @@
<?php
declare(strict_types=1);
namespace App\Kernel\Object;
interface HasRolesWithPermissions extends HasRoles, HasPermissions {}

View File

@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace App\Kernel\Object;
interface HasUuidAsIdentifier
{
public function id(): string;
}

View 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
View File

@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
namespace App\Kernel\Role;
enum Role: string
{
case Admin = 'admin';
case User = 'user';
}

View 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);
}
}

View 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]+$';
}

View File

@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace App\Kernel\String;
enum String: string
{
case Empty = '';
}