mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-11 01:24:46 +02:00
refactor: migration from laravel-enum package to native php enums (#585)
* refactor: migration from laravel-enum package to native php enums * style: fix StyleCI findings
This commit is contained in:
@@ -50,7 +50,7 @@ class ActionResult
|
||||
*/
|
||||
public function hasFailed(): bool
|
||||
{
|
||||
return ActionStatus::FAILED()->is($this->status);
|
||||
return ActionStatus::FAILED === $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -59,7 +59,7 @@ class IndexAction
|
||||
$this->sort($builder, $query, $schema, $scope);
|
||||
|
||||
// paginate
|
||||
$paginationCriteria = $query->getPagingCriteria(PaginationStrategy::OFFSET());
|
||||
$paginationCriteria = $query->getPagingCriteria(PaginationStrategy::OFFSET);
|
||||
|
||||
return $paginationCriteria !== null
|
||||
? $paginationCriteria->paginate($builder)
|
||||
@@ -77,7 +77,7 @@ class IndexAction
|
||||
public function search(
|
||||
Query $query,
|
||||
Schema $schema,
|
||||
PaginationStrategy $paginationStrategy = new PaginationStrategy(PaginationStrategy::OFFSET)
|
||||
PaginationStrategy $paginationStrategy = PaginationStrategy::OFFSET
|
||||
): Collection|Paginator {
|
||||
$search = $this->getSearch();
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ abstract class BackfillAnimeResourceAction extends BackfillResourceAction
|
||||
->first();
|
||||
|
||||
if ($resource === null) {
|
||||
Log::info("Creating {$this->getSite()->description} Resource '$id'");
|
||||
Log::info("Creating {$this->getSite()->localize()} Resource '$id'");
|
||||
|
||||
$resource = ExternalResource::query()->create([
|
||||
ExternalResource::ATTRIBUTE_EXTERNAL_ID => $id,
|
||||
|
||||
@@ -25,7 +25,7 @@ class BackfillLargeCoverImageAction extends BackfillAnimeImageAction
|
||||
*/
|
||||
protected function getFacet(): ImageFacet
|
||||
{
|
||||
return ImageFacet::COVER_LARGE();
|
||||
return ImageFacet::COVER_LARGE;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,7 +37,7 @@ class BackfillLargeCoverImageAction extends BackfillAnimeImageAction
|
||||
*/
|
||||
protected function getImage(): ?Image
|
||||
{
|
||||
$anilistResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::ANILIST);
|
||||
$anilistResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::ANILIST->value);
|
||||
if ($anilistResource instanceof ExternalResource) {
|
||||
return $this->getAnilistImage($anilistResource);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class BackfillSmallCoverImageAction extends BackfillAnimeImageAction
|
||||
*/
|
||||
protected function getFacet(): ImageFacet
|
||||
{
|
||||
return ImageFacet::COVER_SMALL();
|
||||
return ImageFacet::COVER_SMALL;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,7 +37,7 @@ class BackfillSmallCoverImageAction extends BackfillAnimeImageAction
|
||||
*/
|
||||
protected function getImage(): ?Image
|
||||
{
|
||||
$anilistResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::ANILIST);
|
||||
$anilistResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::ANILIST->value);
|
||||
if ($anilistResource instanceof ExternalResource) {
|
||||
return $this->getAnilistImage($anilistResource);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class BackfillAnidbResourceAction extends BackfillAnimeResourceAction
|
||||
*/
|
||||
protected function getSite(): ResourceSite
|
||||
{
|
||||
return ResourceSite::ANIDB();
|
||||
return ResourceSite::ANIDB;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,7 +38,7 @@ class BackfillAnidbResourceAction extends BackfillAnimeResourceAction
|
||||
{
|
||||
// Allow fall-throughs in case AniDB Resource is not mapped to every external site.
|
||||
|
||||
$malResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::MAL);
|
||||
$malResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::MAL->value);
|
||||
if ($malResource instanceof ExternalResource) {
|
||||
$anidbResource = $this->getAnidbMapping($malResource, 'myanimelist');
|
||||
if ($anidbResource !== null) {
|
||||
@@ -49,7 +49,7 @@ class BackfillAnidbResourceAction extends BackfillAnimeResourceAction
|
||||
Sleep::for(rand(1, 3))->second();
|
||||
}
|
||||
|
||||
$anilistResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::ANILIST);
|
||||
$anilistResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::ANILIST->value);
|
||||
if ($anilistResource instanceof ExternalResource) {
|
||||
$anidbResource = $this->getAnidbMapping($anilistResource, 'anilist');
|
||||
if ($anidbResource !== null) {
|
||||
@@ -60,7 +60,7 @@ class BackfillAnidbResourceAction extends BackfillAnimeResourceAction
|
||||
Sleep::for(rand(1, 3))->second();
|
||||
}
|
||||
|
||||
$kitsuResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::KITSU);
|
||||
$kitsuResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::KITSU->value);
|
||||
if ($kitsuResource instanceof ExternalResource) {
|
||||
return $this->getAnidbMapping($kitsuResource, 'kitsu');
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class BackfillAnilistResourceAction extends BackfillAnimeResourceAction
|
||||
*/
|
||||
protected function getSite(): ResourceSite
|
||||
{
|
||||
return ResourceSite::ANILIST();
|
||||
return ResourceSite::ANILIST;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,7 +38,7 @@ class BackfillAnilistResourceAction extends BackfillAnimeResourceAction
|
||||
{
|
||||
// Allow fall-throughs in case Anilist Resource is not mapped to every external site.
|
||||
|
||||
$malResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::MAL);
|
||||
$malResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::MAL->value);
|
||||
if ($malResource instanceof ExternalResource) {
|
||||
$anilistResource = $this->getMalAnilistMapping($malResource);
|
||||
if ($anilistResource !== null) {
|
||||
@@ -46,7 +46,7 @@ class BackfillAnilistResourceAction extends BackfillAnimeResourceAction
|
||||
}
|
||||
}
|
||||
|
||||
$kitsuResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::KITSU);
|
||||
$kitsuResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::KITSU->value);
|
||||
if ($kitsuResource instanceof ExternalResource) {
|
||||
$anilistResource = $this->getKitsuAnilistMapping($kitsuResource);
|
||||
if ($anilistResource !== null) {
|
||||
@@ -54,7 +54,7 @@ class BackfillAnilistResourceAction extends BackfillAnimeResourceAction
|
||||
}
|
||||
}
|
||||
|
||||
$anidbResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::ANIDB);
|
||||
$anidbResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::ANIDB->value);
|
||||
if ($anidbResource instanceof ExternalResource) {
|
||||
return $this->getAnidbAnilistMapping($anidbResource);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class BackfillAnnResourceAction extends BackfillAnimeResourceAction
|
||||
*/
|
||||
protected function getSite(): ResourceSite
|
||||
{
|
||||
return ResourceSite::ANN();
|
||||
return ResourceSite::ANN;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,7 +36,7 @@ class BackfillAnnResourceAction extends BackfillAnimeResourceAction
|
||||
*/
|
||||
protected function getResource(): ?ExternalResource
|
||||
{
|
||||
$kitsuResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::KITSU);
|
||||
$kitsuResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::KITSU->value);
|
||||
if ($kitsuResource instanceof ExternalResource) {
|
||||
return $this->getKitsuAnnMapping($kitsuResource);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class BackfillKitsuResourceAction extends BackfillAnimeResourceAction
|
||||
*/
|
||||
protected function getSite(): ResourceSite
|
||||
{
|
||||
return ResourceSite::KITSU();
|
||||
return ResourceSite::KITSU;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,7 +39,7 @@ class BackfillKitsuResourceAction extends BackfillAnimeResourceAction
|
||||
{
|
||||
// Allow fall-throughs in case Kitsu Resource is not mapped to every external site.
|
||||
|
||||
$malResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::MAL);
|
||||
$malResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::MAL->value);
|
||||
if ($malResource instanceof ExternalResource) {
|
||||
$kitsuResource = $this->getKitsuMapping($malResource, 'MYANIMELIST_ANIME');
|
||||
if ($kitsuResource !== null) {
|
||||
@@ -50,7 +50,7 @@ class BackfillKitsuResourceAction extends BackfillAnimeResourceAction
|
||||
Sleep::for(rand(1, 3))->second();
|
||||
}
|
||||
|
||||
$anilistResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::ANILIST);
|
||||
$anilistResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::ANILIST->value);
|
||||
if ($anilistResource instanceof ExternalResource) {
|
||||
$kitsuResource = $this->getKitsuMapping($anilistResource, 'ANILIST_ANIME');
|
||||
if ($kitsuResource !== null) {
|
||||
@@ -61,7 +61,7 @@ class BackfillKitsuResourceAction extends BackfillAnimeResourceAction
|
||||
Sleep::for(rand(1, 3))->second();
|
||||
}
|
||||
|
||||
$anidbResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::ANIDB);
|
||||
$anidbResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::ANIDB->value);
|
||||
if ($anidbResource instanceof ExternalResource) {
|
||||
$kitsuResource = $this->getKitsuMapping($anidbResource, 'ANIDB');
|
||||
if ($kitsuResource !== null) {
|
||||
@@ -72,7 +72,7 @@ class BackfillKitsuResourceAction extends BackfillAnimeResourceAction
|
||||
Sleep::for(rand(1, 3))->second();
|
||||
}
|
||||
|
||||
$annResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::ANN);
|
||||
$annResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::ANN->value);
|
||||
if ($annResource instanceof ExternalResource) {
|
||||
return $this->getKitsuMapping($annResource, 'ANIMENEWSNETWORK');
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class BackfillMalResourceAction extends BackfillAnimeResourceAction
|
||||
*/
|
||||
protected function getSite(): ResourceSite
|
||||
{
|
||||
return ResourceSite::MAL();
|
||||
return ResourceSite::MAL;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,7 +36,7 @@ class BackfillMalResourceAction extends BackfillAnimeResourceAction
|
||||
*/
|
||||
protected function getResource(): ?ExternalResource
|
||||
{
|
||||
$kitsuResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::KITSU);
|
||||
$kitsuResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::KITSU->value);
|
||||
if ($kitsuResource instanceof ExternalResource) {
|
||||
$malResource = $this->getKitsuMalMapping($kitsuResource);
|
||||
if ($malResource !== null) {
|
||||
@@ -44,7 +44,7 @@ class BackfillMalResourceAction extends BackfillAnimeResourceAction
|
||||
}
|
||||
}
|
||||
|
||||
$anilistResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::ANILIST);
|
||||
$anilistResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::ANILIST->value);
|
||||
if ($anilistResource instanceof ExternalResource) {
|
||||
$malResource = $this->getAnilistMalMapping($anilistResource);
|
||||
if ($malResource !== null) {
|
||||
@@ -52,7 +52,7 @@ class BackfillMalResourceAction extends BackfillAnimeResourceAction
|
||||
}
|
||||
}
|
||||
|
||||
$anidbResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::ANIDB);
|
||||
$anidbResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::ANIDB->value);
|
||||
if ($anidbResource instanceof ExternalResource) {
|
||||
return $this->getAnidbMalMapping($anidbResource);
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ class BackfillAnimeStudiosAction extends BackfillStudiosAction
|
||||
*/
|
||||
protected function getStudios(): array
|
||||
{
|
||||
$malResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::MAL);
|
||||
$malResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::MAL->value);
|
||||
if ($malResource instanceof ExternalResource) {
|
||||
$studios = $this->getMalAnimeStudios($malResource);
|
||||
if (! empty($studios)) {
|
||||
@@ -70,7 +70,7 @@ class BackfillAnimeStudiosAction extends BackfillStudiosAction
|
||||
}
|
||||
}
|
||||
|
||||
$anilistResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::ANILIST);
|
||||
$anilistResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::ANILIST->value);
|
||||
if ($anilistResource instanceof ExternalResource) {
|
||||
$studios = $this->getAnilistAnimeStudios($anilistResource);
|
||||
if (! empty($studios)) {
|
||||
@@ -78,7 +78,7 @@ class BackfillAnimeStudiosAction extends BackfillStudiosAction
|
||||
}
|
||||
}
|
||||
|
||||
$kitsuResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::KITSU);
|
||||
$kitsuResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::KITSU->value);
|
||||
if ($kitsuResource instanceof ExternalResource) {
|
||||
return $this->getKitsuAnimeStudios($kitsuResource);
|
||||
}
|
||||
@@ -119,7 +119,7 @@ class BackfillAnimeStudiosAction extends BackfillStudiosAction
|
||||
|
||||
$studios[] = $studio;
|
||||
|
||||
$this->ensureStudioHasResource($studio, ResourceSite::MAL(), $id);
|
||||
$this->ensureStudioHasResource($studio, ResourceSite::MAL, $id);
|
||||
}
|
||||
|
||||
return $studios;
|
||||
@@ -175,7 +175,7 @@ class BackfillAnimeStudiosAction extends BackfillStudiosAction
|
||||
|
||||
$studios[] = $studio;
|
||||
|
||||
$this->ensureStudioHasResource($studio, ResourceSite::ANILIST(), $id);
|
||||
$this->ensureStudioHasResource($studio, ResourceSite::ANILIST, $id);
|
||||
}
|
||||
|
||||
return $studios;
|
||||
|
||||
@@ -43,7 +43,7 @@ abstract class BackfillImageAction extends BackfillAction
|
||||
if ($this->relation()->getQuery()->where(Image::ATTRIBUTE_FACET, $this->getFacet()->value)->exists()) {
|
||||
Log::info("{$this->label()} '{$this->getModel()->getName()}' already has Image of Facet '{$this->getFacet()->value}'.");
|
||||
|
||||
return new ActionResult(ActionStatus::SKIPPED());
|
||||
return new ActionResult(ActionStatus::SKIPPED);
|
||||
}
|
||||
|
||||
$image = $this->getImage();
|
||||
@@ -54,8 +54,8 @@ abstract class BackfillImageAction extends BackfillAction
|
||||
|
||||
if ($this->relation()->getQuery()->where(Image::ATTRIBUTE_FACET, $this->getFacet()->value)->doesntExist()) {
|
||||
return new ActionResult(
|
||||
ActionStatus::FAILED(),
|
||||
"{$this->label()} '{$this->getModel()->getName()}' has no {$this->getFacet()->description} Image after backfilling. Please review."
|
||||
ActionStatus::FAILED,
|
||||
"{$this->label()} '{$this->getModel()->getName()}' has no {$this->getFacet()->localize()} Image after backfilling. Please review."
|
||||
);
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ abstract class BackfillImageAction extends BackfillAction
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return new ActionResult(ActionStatus::PASSED());
|
||||
return new ActionResult(ActionStatus::PASSED);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,7 +109,7 @@ abstract class BackfillImageAction extends BackfillAction
|
||||
{
|
||||
return Str::of(Str::kebab(class_basename($this->getModel())))
|
||||
->append(DIRECTORY_SEPARATOR)
|
||||
->append(Str::kebab($this->getFacet()->description))
|
||||
->append(Str::kebab($this->getFacet()->localize()))
|
||||
->__toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ abstract class BackfillResourceAction extends BackfillAction
|
||||
if ($this->relation()->getQuery()->where(ExternalResource::ATTRIBUTE_SITE, $this->getSite()->value)->exists()) {
|
||||
Log::info("{$this->label()} '{$this->getModel()->getName()}' already has Resource of Site '{$this->getSite()->value}'.");
|
||||
|
||||
return new ActionResult(ActionStatus::SKIPPED());
|
||||
return new ActionResult(ActionStatus::SKIPPED);
|
||||
}
|
||||
|
||||
$resource = $this->getResource();
|
||||
@@ -49,8 +49,8 @@ abstract class BackfillResourceAction extends BackfillAction
|
||||
|
||||
if ($this->relation()->getQuery()->where(ExternalResource::ATTRIBUTE_SITE, $this->getSite()->value)->doesntExist()) {
|
||||
return new ActionResult(
|
||||
ActionStatus::FAILED(),
|
||||
"{$this->label()} '{$this->getModel()->getName()}' has no {$this->getSite()->description} Resource after backfilling. Please review."
|
||||
ActionStatus::FAILED,
|
||||
"{$this->label()} '{$this->getModel()->getName()}' has no {$this->getSite()->localize()} Resource after backfilling. Please review."
|
||||
);
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ abstract class BackfillResourceAction extends BackfillAction
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return new ActionResult(ActionStatus::PASSED());
|
||||
return new ActionResult(ActionStatus::PASSED);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,7 +41,7 @@ abstract class BackfillStudiosAction extends BackfillAction
|
||||
if ($this->relation()->getQuery()->exists()) {
|
||||
Log::info("{$this->label()} '{$this->getModel()->getName()}' already has Studios.");
|
||||
|
||||
return new ActionResult(ActionStatus::SKIPPED());
|
||||
return new ActionResult(ActionStatus::SKIPPED);
|
||||
}
|
||||
|
||||
$studios = $this->getStudios();
|
||||
@@ -52,7 +52,7 @@ abstract class BackfillStudiosAction extends BackfillAction
|
||||
|
||||
if ($this->relation()->getQuery()->doesntExist()) {
|
||||
return new ActionResult(
|
||||
ActionStatus::FAILED(),
|
||||
ActionStatus::FAILED,
|
||||
"{$this->label()} '{$this->getModel()->getName()}' has no Studios after backfilling. Please review."
|
||||
);
|
||||
}
|
||||
@@ -66,7 +66,7 @@ abstract class BackfillStudiosAction extends BackfillAction
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return new ActionResult(ActionStatus::PASSED());
|
||||
return new ActionResult(ActionStatus::PASSED);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,7 +23,7 @@ class BackfillLargeCoverImageAction extends BackfillStudioImageAction
|
||||
*/
|
||||
protected function getFacet(): ImageFacet
|
||||
{
|
||||
return ImageFacet::COVER_LARGE();
|
||||
return ImageFacet::COVER_LARGE;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,7 +35,7 @@ class BackfillLargeCoverImageAction extends BackfillStudioImageAction
|
||||
*/
|
||||
protected function getImage(): ?Image
|
||||
{
|
||||
$malResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::MAL);
|
||||
$malResource = $this->getModel()->resources()->firstWhere(ExternalResource::ATTRIBUTE_SITE, ResourceSite::MAL->value);
|
||||
if ($malResource instanceof ExternalResource) {
|
||||
return $this->getMalImage($malResource);
|
||||
}
|
||||
|
||||
@@ -46,8 +46,8 @@ class BackfillAudioAction extends BackfillAction
|
||||
*/
|
||||
public function __construct(
|
||||
Video $video,
|
||||
protected readonly DeriveSourceVideo $deriveSourceVideo = new DeriveSourceVideo(DeriveSourceVideo::YES),
|
||||
protected readonly OverwriteAudio $overwriteAudio = new OverwriteAudio(OverwriteAudio::NO)
|
||||
protected readonly DeriveSourceVideo $deriveSourceVideo = DeriveSourceVideo::YES,
|
||||
protected readonly OverwriteAudio $overwriteAudio = OverwriteAudio::NO
|
||||
) {
|
||||
parent::__construct($video);
|
||||
}
|
||||
@@ -67,7 +67,7 @@ class BackfillAudioAction extends BackfillAction
|
||||
if ($this->relation()->getQuery()->exists() && ! $this->overwriteAudio()) {
|
||||
Log::info("{$this->label()} '{$this->getModel()->getName()}' already has Audio'.");
|
||||
|
||||
return new ActionResult(ActionStatus::SKIPPED());
|
||||
return new ActionResult(ActionStatus::SKIPPED);
|
||||
}
|
||||
|
||||
$audio = $this->getAudio();
|
||||
@@ -78,7 +78,7 @@ class BackfillAudioAction extends BackfillAction
|
||||
|
||||
if ($this->relation()->getQuery()->doesntExist()) {
|
||||
return new ActionResult(
|
||||
ActionStatus::FAILED(),
|
||||
ActionStatus::FAILED,
|
||||
"{$this->label()} '{$this->getModel()->getName()}' has no Audio after backfilling. Please review."
|
||||
);
|
||||
}
|
||||
@@ -92,7 +92,7 @@ class BackfillAudioAction extends BackfillAction
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return new ActionResult(ActionStatus::PASSED());
|
||||
return new ActionResult(ActionStatus::PASSED);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,7 +122,7 @@ class BackfillAudioAction extends BackfillAction
|
||||
*/
|
||||
protected function deriveSourceVideo(): bool
|
||||
{
|
||||
return DeriveSourceVideo::YES()->is($this->deriveSourceVideo);
|
||||
return DeriveSourceVideo::YES === $this->deriveSourceVideo;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,7 +132,7 @@ class BackfillAudioAction extends BackfillAction
|
||||
*/
|
||||
protected function overwriteAudio(): bool
|
||||
{
|
||||
return OverwriteAudio::YES()->is($this->overwriteAudio);
|
||||
return OverwriteAudio::YES === $this->overwriteAudio;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -40,7 +40,7 @@ class ReconcileBalanceRepositoriesAction extends ReconcileRepositoriesAction
|
||||
*/
|
||||
protected function diffCallbackForCreateDelete(): Closure
|
||||
{
|
||||
return fn (Balance $first, Balance $second) => $first->date->format(AllowedDateFormat::YM) <=> $second->date->format(AllowedDateFormat::YM);
|
||||
return fn (Balance $first, Balance $second) => $first->date->format(AllowedDateFormat::YM->value) <=> $second->date->format(AllowedDateFormat::YM->value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,8 +67,8 @@ class ReconcileBalanceRepositoriesAction extends ReconcileRepositoriesAction
|
||||
*/
|
||||
protected function diffCallbackForUpdate(): Closure
|
||||
{
|
||||
return fn (Balance $first, Balance $second) => [$first->date->format(AllowedDateFormat::YMD), $first->usage, $first->balance]
|
||||
<=> [$second->date->format(AllowedDateFormat::YMD), $second->usage, $second->balance];
|
||||
return fn (Balance $first, Balance $second) => [$first->date->format(AllowedDateFormat::YMD->value), $first->usage, $first->balance]
|
||||
<=> [$second->date->format(AllowedDateFormat::YMD->value), $second->usage, $second->balance];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,10 +80,10 @@ class ReconcileBalanceRepositoriesAction extends ReconcileRepositoriesAction
|
||||
*/
|
||||
protected function resolveUpdatedModel(Collection $sourceModels, Model $destinationModel): ?Model
|
||||
{
|
||||
$formattedDestinationDate = $destinationModel->getAttribute(Balance::ATTRIBUTE_DATE)->format(AllowedDateFormat::YM);
|
||||
$formattedDestinationDate = $destinationModel->getAttribute(Balance::ATTRIBUTE_DATE)->format(AllowedDateFormat::YM->value);
|
||||
|
||||
return $sourceModels->first(
|
||||
fn (Balance $balance) => $balance->date->format(AllowedDateFormat::YM) === $formattedDestinationDate
|
||||
fn (Balance $balance) => $balance->date->format(AllowedDateFormat::YM->value) === $formattedDestinationDate
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -42,8 +42,8 @@ class ReconcileTransactionRepositoriesAction extends ReconcileRepositoriesAction
|
||||
*/
|
||||
protected function diffCallbackForCreateDelete(): Closure
|
||||
{
|
||||
return fn (Transaction $first, Transaction $second) => [$first->external_id, $first->date->format(AllowedDateFormat::YMD), $first->amount]
|
||||
<=> [$second->external_id, $second->date->format(AllowedDateFormat::YMD), $second->amount];
|
||||
return fn (Transaction $first, Transaction $second) => [$first->external_id, $first->date->format(AllowedDateFormat::YMD->value), $first->amount]
|
||||
<=> [$second->external_id, $second->date->format(AllowedDateFormat::YMD->value), $second->amount];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -32,7 +32,7 @@ abstract class ReconcileResults extends ActionResult
|
||||
protected readonly Collection $deleted = new Collection(),
|
||||
protected readonly Collection $updated = new Collection()
|
||||
) {
|
||||
parent::__construct(ActionStatus::PASSED());
|
||||
parent::__construct(ActionStatus::PASSED);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -60,7 +60,7 @@ abstract class DumpAction
|
||||
$dumper = $this->getDumper($connection);
|
||||
if ($dumper === null) {
|
||||
return new ActionResult(
|
||||
ActionStatus::FAILED(),
|
||||
ActionStatus::FAILED,
|
||||
"Unrecognized connection '{$connection->getName()}'"
|
||||
);
|
||||
}
|
||||
@@ -78,7 +78,7 @@ abstract class DumpAction
|
||||
File::delete($dumpFile);
|
||||
} catch (Exception $e) {
|
||||
return new ActionResult(
|
||||
ActionStatus::FAILED(),
|
||||
ActionStatus::FAILED,
|
||||
$e->getMessage()
|
||||
);
|
||||
}
|
||||
@@ -88,7 +88,7 @@ abstract class DumpAction
|
||||
$reconcileResults->toLog();
|
||||
|
||||
return new ActionResult(
|
||||
ActionStatus::PASSED(),
|
||||
ActionStatus::PASSED,
|
||||
"Database dump '$dumpFile' has been created",
|
||||
);
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ readonly class DeleteResults implements StorageResults
|
||||
{
|
||||
if (empty($this->deletions)) {
|
||||
return new ActionResult(
|
||||
ActionStatus::FAILED(),
|
||||
ActionStatus::FAILED,
|
||||
'No deletions were attempted. Please check that disks are configured.'
|
||||
);
|
||||
}
|
||||
@@ -82,13 +82,13 @@ readonly class DeleteResults implements StorageResults
|
||||
|
||||
if ($failed->isNotEmpty()) {
|
||||
return new ActionResult(
|
||||
ActionStatus::FAILED(),
|
||||
ActionStatus::FAILED,
|
||||
"Failed to delete '{$this->model->getName()}' from disks {$failed->keys()->join(', ', ' & ')}."
|
||||
);
|
||||
}
|
||||
|
||||
return new ActionResult(
|
||||
ActionStatus::PASSED(),
|
||||
ActionStatus::PASSED,
|
||||
"Deleted '{$this->model->getName()}' from disks {$passed->keys()->join(', ', ' & ')}."
|
||||
);
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ readonly class MoveResults implements StorageResults
|
||||
{
|
||||
if (empty($this->moves)) {
|
||||
return new ActionResult(
|
||||
ActionStatus::FAILED(),
|
||||
ActionStatus::FAILED,
|
||||
'No moves were attempted. Please check that disks are configured.'
|
||||
);
|
||||
}
|
||||
@@ -88,13 +88,13 @@ readonly class MoveResults implements StorageResults
|
||||
|
||||
if ($failed->isNotEmpty()) {
|
||||
return new ActionResult(
|
||||
ActionStatus::FAILED(),
|
||||
ActionStatus::FAILED,
|
||||
"Failed to move '{$this->model->getName()}' from '$this->from' to '$this->to' in disks {$failed->keys()->join(', ', ' & ')}."
|
||||
);
|
||||
}
|
||||
|
||||
return new ActionResult(
|
||||
ActionStatus::PASSED(),
|
||||
ActionStatus::PASSED,
|
||||
"Moved '{$this->model->getName()}' from '$this->from' to '$this->to' in disks {$passed->keys()->join(', ', ' & ')}."
|
||||
);
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ readonly class PruneResults implements StorageResults
|
||||
{
|
||||
if (empty($this->prunings)) {
|
||||
return new ActionResult(
|
||||
ActionStatus::FAILED(),
|
||||
ActionStatus::FAILED,
|
||||
'No prunings were attempted.'
|
||||
);
|
||||
}
|
||||
@@ -81,13 +81,13 @@ readonly class PruneResults implements StorageResults
|
||||
|
||||
if ($failed->isNotEmpty()) {
|
||||
return new ActionResult(
|
||||
ActionStatus::FAILED(),
|
||||
ActionStatus::FAILED,
|
||||
"Failed to prune {$failed->keys()->join(', ', ' & ')} from disk '$this->fs'."
|
||||
);
|
||||
}
|
||||
|
||||
return new ActionResult(
|
||||
ActionStatus::PASSED(),
|
||||
ActionStatus::PASSED,
|
||||
"Pruned {$passed->keys()->join(', ', ' & ')} from disk '$this->fs'."
|
||||
);
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ readonly class UploadResults implements StorageResults
|
||||
{
|
||||
if (empty($this->uploads)) {
|
||||
return new ActionResult(
|
||||
ActionStatus::FAILED(),
|
||||
ActionStatus::FAILED,
|
||||
'No uploads were attempted. Please check that disks are configured.'
|
||||
);
|
||||
}
|
||||
@@ -80,13 +80,13 @@ readonly class UploadResults implements StorageResults
|
||||
|
||||
if ($failed->isNotEmpty()) {
|
||||
return new ActionResult(
|
||||
ActionStatus::FAILED(),
|
||||
ActionStatus::FAILED,
|
||||
"Failed to upload to disks {$failed->keys()->join(', ', ' & ')}."
|
||||
);
|
||||
}
|
||||
|
||||
return new ActionResult(
|
||||
ActionStatus::PASSED(),
|
||||
ActionStatus::PASSED,
|
||||
"Uploaded '{$passed->values()->first()}' to disks {$passed->keys()->join(', ', ' & ')}."
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Concerns\Enums;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* Trait CoercesInstances.
|
||||
*/
|
||||
trait CoercesInstances
|
||||
{
|
||||
/**
|
||||
* Attempt to instantiate a new enum using the given name or value.
|
||||
*/
|
||||
public static function unstrictCoerce(mixed $enumKeyOrValue): ?static
|
||||
{
|
||||
return is_numeric($enumKeyOrValue)
|
||||
? static::coerce(intval($enumKeyOrValue))
|
||||
: static::coerce(Str::lower($enumKeyOrValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to instantiate a new enum using the given name or value.
|
||||
*/
|
||||
private static function coerce(mixed $enumNameOrValue): ?static
|
||||
{
|
||||
if ($enumNameOrValue === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($enumNameOrValue instanceof static) {
|
||||
return $enumNameOrValue;
|
||||
}
|
||||
|
||||
$enum = Arr::first(
|
||||
static::cases(),
|
||||
fn (self $enum) => $enum->value === $enumNameOrValue
|
||||
);
|
||||
|
||||
if (is_string($enumNameOrValue) && $enum === null) {
|
||||
$enum = Arr::first(
|
||||
static::cases(),
|
||||
fn (self $enum) => Str::lower($enum->name) === $enumNameOrValue
|
||||
);
|
||||
}
|
||||
|
||||
return $enum;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Concerns\Enums;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* Trait FormatsPermission.
|
||||
*/
|
||||
trait FormatsPermission
|
||||
{
|
||||
/**
|
||||
* Format permission name for model.
|
||||
*
|
||||
* @param string $modelClass
|
||||
* @return string
|
||||
*/
|
||||
public function format(string $modelClass): string
|
||||
{
|
||||
return Str::of($this->value)
|
||||
->append(class_basename($modelClass))
|
||||
->snake(' ')
|
||||
->__toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Concerns\Enums;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Lang;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* Trait LocalizesName.
|
||||
*/
|
||||
trait LocalizesName
|
||||
{
|
||||
/**
|
||||
* Localize the enum.
|
||||
*
|
||||
* @param string|null $locale
|
||||
* @return string|null
|
||||
*/
|
||||
public function localize(?string $locale = null): ?string
|
||||
{
|
||||
return $this->getLocalizedName($locale)
|
||||
?? $this->getPrettyName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the localized name for the derived translation key.
|
||||
*
|
||||
* @param string|null $locale
|
||||
* @return string|null
|
||||
*/
|
||||
protected function getLocalizedName(?string $locale = null): ?string
|
||||
{
|
||||
$localizationKey = $this->getLocalizationKey();
|
||||
|
||||
if (Lang::has($localizationKey, $locale)) {
|
||||
return __($localizationKey);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a pretty-printed version of the enum value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getPrettyName(): string
|
||||
{
|
||||
return Str::of($this->name)
|
||||
->lower()
|
||||
->headline()
|
||||
->__toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default localization key.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getLocalizationKey(): string
|
||||
{
|
||||
return Str::of('enums.')
|
||||
->append(get_class($this))
|
||||
->append('.')
|
||||
->append($this->name)
|
||||
->__toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the enum as an array formatted for a select.
|
||||
*
|
||||
* @param string|null $locale
|
||||
* @return array
|
||||
*/
|
||||
public static function asSelectArray(?string $locale = null): array
|
||||
{
|
||||
$selectArray = [];
|
||||
|
||||
/** @var static $case */
|
||||
foreach (static::cases() as $case) {
|
||||
$selectArray[$case->value] = $case->localize($locale);
|
||||
}
|
||||
|
||||
return $selectArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a new instance from the localized name.
|
||||
*
|
||||
* @param string $localizedName
|
||||
* @param string|null $locale
|
||||
* @return static|null
|
||||
*/
|
||||
public static function fromLocalizedName(string $localizedName, ?string $locale = null): ?static
|
||||
{
|
||||
return Arr::first(
|
||||
static::cases(),
|
||||
fn (self $enum) => Str::lower($enum->localize($locale)) === Str::lower($localizedName)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ namespace App\Concerns\Http\Requests\Api;
|
||||
use App\Contracts\Http\Api\Schema\SchemaInterface;
|
||||
use App\Enums\Http\Api\Filter\BinaryLogicalOperator;
|
||||
use App\Enums\Http\Api\Filter\Clause;
|
||||
use App\Enums\Http\Api\Filter\LogicalOperator;
|
||||
use App\Enums\Http\Api\Filter\UnaryLogicalOperator;
|
||||
use App\Http\Api\Criteria\Filter\Criteria;
|
||||
use App\Http\Api\Filter\Filter;
|
||||
@@ -38,8 +37,8 @@ trait ValidatesFilters
|
||||
foreach ($schema->filters() as $filter) {
|
||||
$schemaFilters = array_merge(
|
||||
$schemaFilters,
|
||||
$this->getFilterFormats($filter, BinaryLogicalOperator::getInstances()),
|
||||
$this->getFilterFormats($filter, UnaryLogicalOperator::getInstances())
|
||||
$this->getFilterFormats($filter, BinaryLogicalOperator::cases()),
|
||||
$this->getFilterFormats($filter, UnaryLogicalOperator::cases())
|
||||
);
|
||||
}
|
||||
|
||||
@@ -50,7 +49,7 @@ trait ValidatesFilters
|
||||
* Get the allowed list of filter keys with possible conditions.
|
||||
*
|
||||
* @param Filter $filter
|
||||
* @param LogicalOperator[] $logicalOperators
|
||||
* @param array<int, BinaryLogicalOperator|UnaryLogicalOperator> $logicalOperators
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getFilterFormats(Filter $filter, array $logicalOperators): array
|
||||
@@ -107,7 +106,7 @@ trait ValidatesFilters
|
||||
*/
|
||||
protected function conditionallyRestrictFilter(Validator $validator, SchemaInterface $schema, Filter $filter): void
|
||||
{
|
||||
$singleValueFilterFormats = $this->getFilterFormats($filter, BinaryLogicalOperator::getInstances());
|
||||
$singleValueFilterFormats = $this->getFilterFormats($filter, BinaryLogicalOperator::cases());
|
||||
foreach ($singleValueFilterFormats as $singleValueFilterFormat) {
|
||||
foreach ($this->getFormattedParameters($schema, $singleValueFilterFormat) as $formattedParameter) {
|
||||
if (collect($validator->getRules())->keys()->doesntContain($formattedParameter)) {
|
||||
@@ -120,11 +119,11 @@ trait ValidatesFilters
|
||||
}
|
||||
}
|
||||
|
||||
if (Clause::WHERE()->is($filter->clause())) {
|
||||
if (Clause::WHERE === $filter->clause()) {
|
||||
$this->validateMultiValueFilterForWhereClause($validator, $schema, $filter);
|
||||
}
|
||||
|
||||
if (Clause::HAVING()->is($filter->clause())) {
|
||||
if (Clause::HAVING === $filter->clause()) {
|
||||
$this->prohibitMultiValueFilterForHavingClause($validator, $schema, $filter);
|
||||
}
|
||||
}
|
||||
@@ -144,7 +143,7 @@ trait ValidatesFilters
|
||||
$multiValueRules[] = new DelimitedRule($rule);
|
||||
}
|
||||
|
||||
$multiValueFilterFormats = $this->getFilterFormats($filter, UnaryLogicalOperator::getInstances());
|
||||
$multiValueFilterFormats = $this->getFilterFormats($filter, UnaryLogicalOperator::cases());
|
||||
foreach ($multiValueFilterFormats as $multiValueFilterFormat) {
|
||||
foreach ($this->getFormattedParameters($schema, $multiValueFilterFormat) as $formattedParameter) {
|
||||
if (collect($validator->getRules())->keys()->doesntContain($formattedParameter)) {
|
||||
@@ -168,7 +167,7 @@ trait ValidatesFilters
|
||||
*/
|
||||
protected function prohibitMultiValueFilterForHavingClause(Validator $validator, SchemaInterface $schema, Filter $filter): void
|
||||
{
|
||||
$multiValueFilterFormats = $this->getFilterFormats($filter, UnaryLogicalOperator::getInstances());
|
||||
$multiValueFilterFormats = $this->getFilterFormats($filter, UnaryLogicalOperator::cases());
|
||||
foreach ($multiValueFilterFormats as $multiValueFilterFormat) {
|
||||
foreach ($this->getFormattedParameters($schema, $multiValueFilterFormat) as $formattedParameter) {
|
||||
if (collect($validator->getRules())->keys()->doesntContain($formattedParameter)) {
|
||||
|
||||
@@ -27,7 +27,7 @@ trait ValidatesSorts
|
||||
$allowedSorts = [];
|
||||
|
||||
foreach ($schema->sorts() as $sort) {
|
||||
foreach (Direction::getInstances() as $direction) {
|
||||
foreach (Direction::cases() as $direction) {
|
||||
$allowedSorts[] = $sort->format($direction);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ trait ReconcilesBalanceRepositories
|
||||
{
|
||||
$service = Service::unstrictCoerce(Arr::get($data, 'service'));
|
||||
|
||||
return match ($service?->value) {
|
||||
return match ($service) {
|
||||
Service::DIGITALOCEAN => App::make(DigitalOceanSourceRepository::class),
|
||||
default => null,
|
||||
};
|
||||
@@ -44,7 +44,7 @@ trait ReconcilesBalanceRepositories
|
||||
{
|
||||
$service = Service::unstrictCoerce(Arr::get($data, 'service'));
|
||||
|
||||
return match ($service?->value) {
|
||||
return match ($service) {
|
||||
Service::DIGITALOCEAN => App::make(DigitalOceanDestinationRepository::class),
|
||||
default => null,
|
||||
};
|
||||
|
||||
@@ -28,7 +28,7 @@ trait ReconcilesTransactionRepositories
|
||||
{
|
||||
$service = Service::unstrictCoerce(Arr::get($data, 'service'));
|
||||
|
||||
return match ($service?->value) {
|
||||
return match ($service) {
|
||||
Service::DIGITALOCEAN => App::make(DigitalOceanSourceRepository::class),
|
||||
default => null,
|
||||
};
|
||||
@@ -44,7 +44,7 @@ trait ReconcilesTransactionRepositories
|
||||
{
|
||||
$service = Service::unstrictCoerce(Arr::get($data, 'service'));
|
||||
|
||||
return match ($service?->value) {
|
||||
return match ($service) {
|
||||
Service::DIGITALOCEAN => App::make(DigitalOceanDestinationRepository::class),
|
||||
default => null,
|
||||
};
|
||||
|
||||
@@ -28,7 +28,7 @@ trait ReconcilesRepositories
|
||||
$sourceRepository = $this->getSourceRepository($data);
|
||||
if ($sourceRepository === null) {
|
||||
return new ActionResult(
|
||||
ActionStatus::FAILED(),
|
||||
ActionStatus::FAILED,
|
||||
'Could not find source repository'
|
||||
);
|
||||
}
|
||||
@@ -36,7 +36,7 @@ trait ReconcilesRepositories
|
||||
$destinationRepository = $this->getDestinationRepository($data);
|
||||
if ($destinationRepository === null) {
|
||||
return new ActionResult(
|
||||
ActionStatus::FAILED(),
|
||||
ActionStatus::FAILED,
|
||||
'Could not find destination repository'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace App\Console\Commands\Repositories\Billing;
|
||||
|
||||
use App\Console\Commands\Repositories\ReconcileCommand;
|
||||
use App\Enums\Models\Billing\Service;
|
||||
use BenSampo\Enum\Rules\EnumKey;
|
||||
use App\Rules\Api\EnumLocalizedNameRule;
|
||||
use Illuminate\Contracts\Validation\Validator;
|
||||
use Illuminate\Support\Facades\Validator as ValidatorFacade;
|
||||
|
||||
@@ -23,7 +23,7 @@ abstract class ServiceReconcileCommand extends ReconcileCommand
|
||||
protected function validator(): Validator
|
||||
{
|
||||
return ValidatorFacade::make($this->arguments(), [
|
||||
'service' => ['required', new EnumKey(Service::class)],
|
||||
'service' => ['required', new EnumLocalizedNameRule(Service::class)],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class Kernel extends ConsoleKernel
|
||||
*/
|
||||
protected function schedule(Schedule $schedule): void
|
||||
{
|
||||
$schedule->command(BalanceReconcileCommand::class, [Service::DIGITALOCEAN()->key])
|
||||
$schedule->command(BalanceReconcileCommand::class, [Service::DIGITALOCEAN->name])
|
||||
->withoutOverlapping()
|
||||
->runInBackground()
|
||||
->storeOutput()
|
||||
@@ -126,7 +126,7 @@ class Kernel extends ConsoleKernel
|
||||
->storeOutput()
|
||||
->everyFiveMinutes();
|
||||
|
||||
$schedule->command(TransactionReconcileCommand::class, [Service::DIGITALOCEAN()->key])
|
||||
$schedule->command(TransactionReconcileCommand::class, [Service::DIGITALOCEAN->name])
|
||||
->withoutOverlapping()
|
||||
->runInBackground()
|
||||
->storeOutput()
|
||||
|
||||
@@ -5,7 +5,6 @@ declare(strict_types=1);
|
||||
namespace App\Discord;
|
||||
|
||||
use App\Enums\Http\Api\Filter\AllowedDateFormat;
|
||||
use BenSampo\Enum\Enum;
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Str;
|
||||
@@ -73,13 +72,13 @@ class DiscordEmbedField implements Arrayable, JsonSerializable
|
||||
protected function formatEmbedFieldValue(mixed $value): string
|
||||
{
|
||||
// Use description for enums
|
||||
if ($value instanceof Enum) {
|
||||
return $value->description;
|
||||
if (is_object($value) && enum_exists(get_class($value))) {
|
||||
return $value->localize();
|
||||
}
|
||||
|
||||
// Use 'Y-m-d' format for dates
|
||||
if ($value instanceof Carbon) {
|
||||
return $value->format(AllowedDateFormat::YMD);
|
||||
return $value->format(AllowedDateFormat::YMD->value);
|
||||
}
|
||||
|
||||
// Pretty print booleans
|
||||
|
||||
@@ -4,18 +4,12 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Enums\Actions;
|
||||
|
||||
use App\Enums\BaseEnum;
|
||||
|
||||
/**
|
||||
* Class ActionStatus.
|
||||
*
|
||||
* @method static static PASSED()
|
||||
* @method static static FAILED()
|
||||
* @method static static SKIPPED()
|
||||
* Enum ActionStatus.
|
||||
*/
|
||||
final class ActionStatus extends BaseEnum
|
||||
enum ActionStatus
|
||||
{
|
||||
public const PASSED = 0;
|
||||
public const FAILED = 1;
|
||||
public const SKIPPED = 2;
|
||||
case PASSED;
|
||||
case FAILED;
|
||||
case SKIPPED;
|
||||
}
|
||||
|
||||
@@ -4,16 +4,15 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Enums\Actions\Models\Wiki\Video;
|
||||
|
||||
use App\Enums\BaseEnum;
|
||||
use App\Concerns\Enums\LocalizesName;
|
||||
|
||||
/**
|
||||
* Class DeriveSourceVideo.
|
||||
*
|
||||
* @method static static YES()
|
||||
* @method static static NO()
|
||||
* Enum DeriveSourceVideo.
|
||||
*/
|
||||
final class DeriveSourceVideo extends BaseEnum
|
||||
enum DeriveSourceVideo: int
|
||||
{
|
||||
public const YES = 0;
|
||||
public const NO = 1;
|
||||
use LocalizesName;
|
||||
|
||||
case NO = 0;
|
||||
case YES = 1;
|
||||
}
|
||||
|
||||
@@ -4,16 +4,15 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Enums\Actions\Models\Wiki\Video;
|
||||
|
||||
use App\Enums\BaseEnum;
|
||||
use App\Concerns\Enums\LocalizesName;
|
||||
|
||||
/**
|
||||
* Class OverwriteAudio.
|
||||
*
|
||||
* @method static static YES()
|
||||
* @method static static NO()
|
||||
* Enum OverwriteAudio.
|
||||
*/
|
||||
final class OverwriteAudio extends BaseEnum
|
||||
enum OverwriteAudio: int
|
||||
{
|
||||
public const YES = 0;
|
||||
public const NO = 1;
|
||||
use LocalizesName;
|
||||
|
||||
case NO = 0;
|
||||
case YES = 1;
|
||||
}
|
||||
|
||||
@@ -4,38 +4,20 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Enums\Auth;
|
||||
|
||||
use App\Enums\BaseEnum;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Concerns\Enums\FormatsPermission;
|
||||
|
||||
/**
|
||||
* Class CrudPermissions.
|
||||
*
|
||||
* @method static static CREATE()
|
||||
* @method static static DELETE()
|
||||
* @method static static UPDATE()
|
||||
* @method static static VIEW()
|
||||
* Enum CrudPermissions.
|
||||
*/
|
||||
class CrudPermission extends BaseEnum
|
||||
enum CrudPermission: string
|
||||
{
|
||||
public const CREATE = 'create';
|
||||
use FormatsPermission;
|
||||
|
||||
public const DELETE = 'delete';
|
||||
case CREATE = 'create';
|
||||
|
||||
public const UPDATE = 'update';
|
||||
case DELETE = 'delete';
|
||||
|
||||
public const VIEW = 'view';
|
||||
case UPDATE = 'update';
|
||||
|
||||
/**
|
||||
* Format permission name for model.
|
||||
*
|
||||
* @param string $modelClass
|
||||
* @return string
|
||||
*/
|
||||
public function format(string $modelClass): string
|
||||
{
|
||||
return Str::of($this->value)
|
||||
->append(class_basename($modelClass))
|
||||
->snake(' ')
|
||||
->__toString();
|
||||
}
|
||||
case VIEW = 'view';
|
||||
}
|
||||
|
||||
@@ -4,15 +4,16 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Enums\Auth;
|
||||
|
||||
/**
|
||||
* Class ExtendedCrudPermission.
|
||||
*
|
||||
* @method static static FORCE_DELETE()
|
||||
* @method static static RESTORE()
|
||||
*/
|
||||
final class ExtendedCrudPermission extends CrudPermission
|
||||
{
|
||||
public const FORCE_DELETE = 'force delete';
|
||||
use App\Concerns\Enums\FormatsPermission;
|
||||
|
||||
public const RESTORE = 'restore';
|
||||
/**
|
||||
* Enum ExtendedCrudPermission.
|
||||
*/
|
||||
enum ExtendedCrudPermission: string
|
||||
{
|
||||
use FormatsPermission;
|
||||
|
||||
case FORCE_DELETE = 'force delete';
|
||||
|
||||
case RESTORE = 'restore';
|
||||
}
|
||||
|
||||
@@ -4,20 +4,18 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Enums\Auth;
|
||||
|
||||
use App\Enums\BaseEnum;
|
||||
|
||||
/**
|
||||
* Class SpecialPermission.
|
||||
* Enum SpecialPermission.
|
||||
*/
|
||||
final class SpecialPermission extends BaseEnum
|
||||
enum SpecialPermission: string
|
||||
{
|
||||
public const BYPASS_API_RATE_LIMITER = 'bypass api rate limiter';
|
||||
case BYPASS_API_RATE_LIMITER = 'bypass api rate limiter';
|
||||
|
||||
public const BYPASS_FEATURE_FLAGS = 'bypass feature flags';
|
||||
case BYPASS_FEATURE_FLAGS = 'bypass feature flags';
|
||||
|
||||
public const VIEW_HORIZON = 'view horizon';
|
||||
case VIEW_HORIZON = 'view horizon';
|
||||
|
||||
public const VIEW_NOVA = 'view nova';
|
||||
case VIEW_NOVA = 'view nova';
|
||||
|
||||
public const VIEW_TELESCOPE = 'view telescope';
|
||||
case VIEW_TELESCOPE = 'view telescope';
|
||||
}
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use BenSampo\Enum\Contracts\LocalizedEnum;
|
||||
use BenSampo\Enum\Enum;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* Class BaseEnum.
|
||||
*/
|
||||
abstract class BaseEnum extends Enum implements LocalizedEnum
|
||||
{
|
||||
/**
|
||||
* Make a new instance from an enum description.
|
||||
*
|
||||
* @param string $description
|
||||
* @return static|null
|
||||
*/
|
||||
public static function fromDescription(string $description): ?static
|
||||
{
|
||||
return Arr::first(
|
||||
static::getInstances(),
|
||||
fn (BaseEnum $enum) => Str::lower($enum->description) === Str::lower($description)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to instantiate a new Enum using the given key or value.
|
||||
* Note: library coerce function does not attempt unstrict value comparision.
|
||||
*/
|
||||
public static function unstrictCoerce(mixed $enumKeyOrValue): ?static
|
||||
{
|
||||
return is_numeric($enumKeyOrValue)
|
||||
? static::coerce(intval($enumKeyOrValue))
|
||||
: static::coerce($enumKeyOrValue);
|
||||
}
|
||||
}
|
||||
@@ -4,18 +4,12 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Enums\Discord;
|
||||
|
||||
use App\Enums\BaseEnum;
|
||||
|
||||
/**
|
||||
* Class EmbedColor.
|
||||
*
|
||||
* @method static static GREEN()
|
||||
* @method static static YELLOW()
|
||||
* @method static static RED()
|
||||
* Enum EmbedColor.
|
||||
*/
|
||||
final class EmbedColor extends BaseEnum
|
||||
enum EmbedColor: int
|
||||
{
|
||||
public const GREEN = 3066993;
|
||||
public const YELLOW = 16776960;
|
||||
public const RED = 15158332;
|
||||
case GREEN = 3066993;
|
||||
case YELLOW = 16776960;
|
||||
case RED = 15158332;
|
||||
}
|
||||
|
||||
@@ -4,24 +4,15 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Enums\Http\Api\Field;
|
||||
|
||||
use App\Enums\BaseEnum;
|
||||
|
||||
/**
|
||||
* Class AggregateFunction.
|
||||
*
|
||||
* @method static static AVG()
|
||||
* @method static static COUNT()
|
||||
* @method static static EXISTS()
|
||||
* @method static static MAX()
|
||||
* @method static static MIN()
|
||||
* @method static static SUM()
|
||||
* Enum AggregateFunction.
|
||||
*/
|
||||
final class AggregateFunction extends BaseEnum
|
||||
enum AggregateFunction: string
|
||||
{
|
||||
public const AVG = 'avg';
|
||||
public const COUNT = 'count';
|
||||
public const EXISTS = 'exists';
|
||||
public const MAX = 'max';
|
||||
public const MIN = 'min';
|
||||
public const SUM = 'sum';
|
||||
case AVG = 'avg';
|
||||
case COUNT = 'count';
|
||||
case EXISTS = 'exists';
|
||||
case MAX = 'max';
|
||||
case MIN = 'min';
|
||||
case SUM = 'sum';
|
||||
}
|
||||
|
||||
@@ -4,18 +4,16 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Enums\Http\Api\Filter;
|
||||
|
||||
use App\Enums\BaseEnum;
|
||||
|
||||
/**
|
||||
* Class AllowedDateFormat.
|
||||
* Enum AllowedDateFormat.
|
||||
*/
|
||||
final class AllowedDateFormat extends BaseEnum
|
||||
enum AllowedDateFormat: string
|
||||
{
|
||||
public const YMDHISU = 'Y-m-d\TH:i:s.u';
|
||||
public const YMDHIS = 'Y-m-d\TH:i:s';
|
||||
public const YMDHI = 'Y-m-d\TH:i';
|
||||
public const YMDH = 'Y-m-d\TH';
|
||||
public const YMD = 'Y-m-d';
|
||||
public const YM = 'Y-m';
|
||||
public const Y = 'Y';
|
||||
case YMDHISU = 'Y-m-d\TH:i:s.u';
|
||||
case YMDHIS = 'Y-m-d\TH:i:s';
|
||||
case YMDHI = 'Y-m-d\TH:i';
|
||||
case YMDH = 'Y-m-d\TH';
|
||||
case YMD = 'Y-m-d';
|
||||
case YM = 'Y-m';
|
||||
case Y = 'Y';
|
||||
}
|
||||
|
||||
@@ -4,14 +4,15 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Enums\Http\Api\Filter;
|
||||
|
||||
use App\Concerns\Enums\CoercesInstances;
|
||||
|
||||
/**
|
||||
* Class BinaryLogicalOperator.
|
||||
*
|
||||
* @method static static AND()
|
||||
* @method static static OR()
|
||||
* Enum BinaryLogicalOperator.
|
||||
*/
|
||||
final class BinaryLogicalOperator extends LogicalOperator
|
||||
enum BinaryLogicalOperator: string
|
||||
{
|
||||
public const AND = 'and';
|
||||
public const OR = 'or';
|
||||
use CoercesInstances;
|
||||
|
||||
case AND = 'and';
|
||||
case OR = 'or';
|
||||
}
|
||||
|
||||
@@ -4,16 +4,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Enums\Http\Api\Filter;
|
||||
|
||||
use App\Enums\BaseEnum;
|
||||
|
||||
/**
|
||||
* Class Clause.
|
||||
*
|
||||
* @method static static WHERE()
|
||||
* @method static static HAVING()
|
||||
* Enum Clause.
|
||||
*/
|
||||
final class Clause extends BaseEnum
|
||||
enum Clause
|
||||
{
|
||||
public const WHERE = 0;
|
||||
public const HAVING = 1;
|
||||
case WHERE;
|
||||
case HAVING;
|
||||
}
|
||||
|
||||
@@ -4,28 +4,21 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Enums\Http\Api\Filter;
|
||||
|
||||
use App\Enums\BaseEnum;
|
||||
use App\Concerns\Enums\CoercesInstances;
|
||||
|
||||
/**
|
||||
* Class ComparisonOperator.
|
||||
*
|
||||
* @method static static EQ()
|
||||
* @method static static NE()
|
||||
* @method static static LT()
|
||||
* @method static static GT()
|
||||
* @method static static LTE()
|
||||
* @method static static GTE()
|
||||
* @method static static LIKE()
|
||||
* @method static static NOTLIKE()
|
||||
* Enum ComparisonOperator.
|
||||
*/
|
||||
final class ComparisonOperator extends BaseEnum
|
||||
enum ComparisonOperator: string
|
||||
{
|
||||
public const EQ = '=';
|
||||
public const NE = '<>';
|
||||
public const LT = '<';
|
||||
public const GT = '>';
|
||||
public const LTE = '<=';
|
||||
public const GTE = '>=';
|
||||
public const LIKE = 'like';
|
||||
public const NOTLIKE = 'not like';
|
||||
use CoercesInstances;
|
||||
|
||||
case EQ = '=';
|
||||
case NE = '<>';
|
||||
case LT = '<';
|
||||
case GT = '>';
|
||||
case LTE = '<=';
|
||||
case GTE = '>=';
|
||||
case LIKE = 'like';
|
||||
case NOTLIKE = 'not like';
|
||||
}
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Enums\Http\Api\Filter;
|
||||
|
||||
use App\Enums\BaseEnum;
|
||||
|
||||
/**
|
||||
* Class LogicalOperator.
|
||||
*/
|
||||
abstract class LogicalOperator extends BaseEnum
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -4,14 +4,16 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Enums\Http\Api\Filter;
|
||||
|
||||
use App\Enums\BaseEnum;
|
||||
use App\Concerns\Enums\LocalizesName;
|
||||
|
||||
/**
|
||||
* Class TrashedStatus.
|
||||
* Enum TrashedStatus.
|
||||
*/
|
||||
final class TrashedStatus extends BaseEnum
|
||||
enum TrashedStatus: string
|
||||
{
|
||||
public const WITH = 'with';
|
||||
public const WITHOUT = 'without';
|
||||
public const ONLY = 'only';
|
||||
use LocalizesName;
|
||||
|
||||
case WITH = 'with';
|
||||
case WITHOUT = 'without';
|
||||
case ONLY = 'only';
|
||||
}
|
||||
|
||||
@@ -4,10 +4,14 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Enums\Http\Api\Filter;
|
||||
|
||||
use App\Concerns\Enums\CoercesInstances;
|
||||
|
||||
/**
|
||||
* Class UnaryLogicalOperator.
|
||||
* Enum UnaryLogicalOperator.
|
||||
*/
|
||||
final class UnaryLogicalOperator extends LogicalOperator
|
||||
enum UnaryLogicalOperator: string
|
||||
{
|
||||
public const NOT = 'not';
|
||||
use CoercesInstances;
|
||||
|
||||
case NOT = 'not';
|
||||
}
|
||||
|
||||
@@ -4,18 +4,12 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Enums\Http\Api\Paging;
|
||||
|
||||
use App\Enums\BaseEnum;
|
||||
|
||||
/**
|
||||
* Class PaginationStrategy.
|
||||
*
|
||||
* @method static static NONE()
|
||||
* @method static static LIMIT()
|
||||
* @method static static OFFSET()
|
||||
* Enum PaginationStrategy.
|
||||
*/
|
||||
final class PaginationStrategy extends BaseEnum
|
||||
enum PaginationStrategy
|
||||
{
|
||||
public const NONE = 0;
|
||||
public const LIMIT = 1;
|
||||
public const OFFSET = 2;
|
||||
case NONE;
|
||||
case LIMIT;
|
||||
case OFFSET;
|
||||
}
|
||||
|
||||
@@ -4,16 +4,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Enums\Http\Api;
|
||||
|
||||
use App\Enums\BaseEnum;
|
||||
|
||||
/**
|
||||
* Class QualifyColumn.
|
||||
*
|
||||
* @method static static YES()
|
||||
* @method static static NO()
|
||||
* Enum QualifyColumn.
|
||||
*/
|
||||
final class QualifyColumn extends BaseEnum
|
||||
enum QualifyColumn
|
||||
{
|
||||
public const YES = 0;
|
||||
public const NO = 1;
|
||||
case YES;
|
||||
case NO;
|
||||
}
|
||||
|
||||
@@ -4,16 +4,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Enums\Http\Api\Sort;
|
||||
|
||||
use App\Enums\BaseEnum;
|
||||
|
||||
/**
|
||||
* Class Direction.
|
||||
*
|
||||
* @method static static ASCENDING()
|
||||
* @method static static DESCENDING()
|
||||
* Enum Direction.
|
||||
*/
|
||||
final class Direction extends BaseEnum
|
||||
enum Direction: string
|
||||
{
|
||||
public const ASCENDING = 'asc';
|
||||
public const DESCENDING = 'desc';
|
||||
case ASCENDING = 'asc';
|
||||
case DESCENDING = 'desc';
|
||||
}
|
||||
|
||||
@@ -4,13 +4,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Enums\Http;
|
||||
|
||||
use App\Enums\BaseEnum;
|
||||
|
||||
/**
|
||||
* Class StreamingMethod.
|
||||
* Enum StreamingMethod.
|
||||
*/
|
||||
class StreamingMethod extends BaseEnum
|
||||
enum StreamingMethod: string
|
||||
{
|
||||
public const NGINX = 'nginx';
|
||||
public const RESPONSE = 'response';
|
||||
case NGINX = 'nginx';
|
||||
case RESPONSE = 'response';
|
||||
}
|
||||
|
||||
@@ -4,16 +4,18 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Enums\Models\Billing;
|
||||
|
||||
use App\Enums\BaseEnum;
|
||||
use App\Concerns\Enums\LocalizesName;
|
||||
|
||||
/**
|
||||
* Class BalanceFrequency.
|
||||
* Enum BalanceFrequency.
|
||||
*/
|
||||
final class BalanceFrequency extends BaseEnum
|
||||
enum BalanceFrequency: int
|
||||
{
|
||||
public const ONCE = 0;
|
||||
public const ANNUALLY = 1;
|
||||
public const BIANNUALLY = 2;
|
||||
public const QUARTERLY = 3;
|
||||
public const MONTHLY = 4;
|
||||
use LocalizesName;
|
||||
|
||||
case ONCE = 0;
|
||||
case ANNUALLY = 1;
|
||||
case BIANNUALLY = 2;
|
||||
case QUARTERLY = 3;
|
||||
case MONTHLY = 4;
|
||||
}
|
||||
|
||||
@@ -4,22 +4,20 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Enums\Models\Billing;
|
||||
|
||||
use App\Enums\BaseEnum;
|
||||
use App\Concerns\Enums\CoercesInstances;
|
||||
use App\Concerns\Enums\LocalizesName;
|
||||
|
||||
/**
|
||||
* Class Service.
|
||||
*
|
||||
* @method static static OTHER()
|
||||
* @method static static DIGITALOCEAN()
|
||||
* @method static static AWS()
|
||||
* @method static static HOVER()
|
||||
* @method static static WALKERSERVERS()
|
||||
* Enum Service.
|
||||
*/
|
||||
final class Service extends BaseEnum
|
||||
enum Service: int
|
||||
{
|
||||
public const OTHER = 0;
|
||||
public const DIGITALOCEAN = 1;
|
||||
public const AWS = 2;
|
||||
public const HOVER = 3;
|
||||
public const WALKERSERVERS = 4;
|
||||
use CoercesInstances;
|
||||
use LocalizesName;
|
||||
|
||||
case OTHER = 0;
|
||||
case DIGITALOCEAN = 1;
|
||||
case AWS = 2;
|
||||
case HOVER = 3;
|
||||
case WALKERSERVERS = 4;
|
||||
}
|
||||
|
||||
@@ -4,18 +4,16 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Enums\Models\List;
|
||||
|
||||
use App\Enums\BaseEnum;
|
||||
use App\Concerns\Enums\LocalizesName;
|
||||
|
||||
/**
|
||||
* Class PlaylistVisibility.
|
||||
*
|
||||
* @method static static PUBLIC()
|
||||
* @method static static PRIVATE()
|
||||
* @method static static UNLISTED()
|
||||
* Enum PlaylistVisibility.
|
||||
*/
|
||||
final class PlaylistVisibility extends BaseEnum
|
||||
enum PlaylistVisibility: int
|
||||
{
|
||||
public const PUBLIC = 0;
|
||||
public const PRIVATE = 1;
|
||||
public const UNLISTED = 2;
|
||||
use LocalizesName;
|
||||
|
||||
case PUBLIC = 0;
|
||||
case PRIVATE = 1;
|
||||
case UNLISTED = 2;
|
||||
}
|
||||
|
||||
@@ -4,15 +4,17 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Enums\Models\Wiki;
|
||||
|
||||
use App\Enums\BaseEnum;
|
||||
use App\Concerns\Enums\LocalizesName;
|
||||
|
||||
/**
|
||||
* Class AnimeSeason.
|
||||
* Enum AnimeSeason.
|
||||
*/
|
||||
final class AnimeSeason extends BaseEnum
|
||||
enum AnimeSeason: int
|
||||
{
|
||||
public const WINTER = 0;
|
||||
public const SPRING = 1;
|
||||
public const SUMMER = 2;
|
||||
public const FALL = 3;
|
||||
use LocalizesName;
|
||||
|
||||
case WINTER = 0;
|
||||
case SPRING = 1;
|
||||
case SUMMER = 2;
|
||||
case FALL = 3;
|
||||
}
|
||||
|
||||
@@ -4,18 +4,16 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Enums\Models\Wiki;
|
||||
|
||||
use App\Enums\BaseEnum;
|
||||
use App\Concerns\Enums\LocalizesName;
|
||||
|
||||
/**
|
||||
* Class ImageFacet.
|
||||
*
|
||||
* @method static static COVER_SMALL()
|
||||
* @method static static COVER_LARGE()
|
||||
* @method static static GRILL()
|
||||
* Enum ImageFacet.
|
||||
*/
|
||||
final class ImageFacet extends BaseEnum
|
||||
enum ImageFacet: int
|
||||
{
|
||||
public const COVER_SMALL = 0;
|
||||
public const COVER_LARGE = 1;
|
||||
public const GRILL = 2;
|
||||
use LocalizesName;
|
||||
|
||||
case COVER_SMALL = 0;
|
||||
case COVER_LARGE = 1;
|
||||
case GRILL = 2;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Enums\Models\Wiki;
|
||||
|
||||
use App\Enums\BaseEnum;
|
||||
use App\Concerns\Enums\LocalizesName;
|
||||
use Illuminate\Http\Client\RequestException;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
@@ -12,52 +12,44 @@ use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* Class ResourceSite.
|
||||
*
|
||||
* @method static static OFFICIAL_SITE()
|
||||
* @method static static TWITTER()
|
||||
* @method static static ANIDB()
|
||||
* @method static static ANILIST()
|
||||
* @method static static ANIME_PLANET()
|
||||
* @method static static ANN()
|
||||
* @method static static KITSU()
|
||||
* @method static static MAL()
|
||||
* @method static static WIKI()
|
||||
* Enum ResourceSite.
|
||||
*/
|
||||
final class ResourceSite extends BaseEnum
|
||||
enum ResourceSite: int
|
||||
{
|
||||
use LocalizesName;
|
||||
|
||||
// Official Media
|
||||
public const OFFICIAL_SITE = 0;
|
||||
public const TWITTER = 1;
|
||||
case OFFICIAL_SITE = 0;
|
||||
case TWITTER = 1;
|
||||
|
||||
// Tracking Sites
|
||||
public const ANIDB = 2;
|
||||
public const ANILIST = 3;
|
||||
public const ANIME_PLANET = 4;
|
||||
public const ANN = 5;
|
||||
public const KITSU = 6;
|
||||
public const MAL = 7;
|
||||
case ANIDB = 2;
|
||||
case ANILIST = 3;
|
||||
case ANIME_PLANET = 4;
|
||||
case ANN = 5;
|
||||
case KITSU = 6;
|
||||
case MAL = 7;
|
||||
|
||||
// Compendia
|
||||
public const WIKI = 8;
|
||||
case WIKI = 8;
|
||||
|
||||
/**
|
||||
* Get domain by resource site.
|
||||
*
|
||||
* @param int|null $value the resource site key
|
||||
* @param int|null $value
|
||||
* @return string|null
|
||||
*/
|
||||
public static function getDomain(?int $value): ?string
|
||||
{
|
||||
return match ($value) {
|
||||
self::TWITTER => 'twitter.com',
|
||||
self::ANIDB => 'anidb.net',
|
||||
self::ANILIST => 'anilist.co',
|
||||
self::ANIME_PLANET => 'www.anime-planet.com',
|
||||
self::ANN => 'www.animenewsnetwork.com',
|
||||
self::KITSU => 'kitsu.io',
|
||||
self::MAL => 'myanimelist.net',
|
||||
self::WIKI => 'wikipedia.org',
|
||||
ResourceSite::TWITTER->value => 'twitter.com',
|
||||
ResourceSite::ANIDB->value => 'anidb.net',
|
||||
ResourceSite::ANILIST->value => 'anilist.co',
|
||||
ResourceSite::ANIME_PLANET->value => 'www.anime-planet.com',
|
||||
ResourceSite::ANN->value => 'www.animenewsnetwork.com',
|
||||
ResourceSite::KITSU->value => 'kitsu.io',
|
||||
ResourceSite::MAL->value => 'myanimelist.net',
|
||||
ResourceSite::WIKI->value => 'wikipedia.org',
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
@@ -65,7 +57,7 @@ final class ResourceSite extends BaseEnum
|
||||
/**
|
||||
* Get resource site by link, matching expected domain.
|
||||
*
|
||||
* @param string $link the link to test
|
||||
* @param string $link
|
||||
* @return ResourceSite|null
|
||||
*/
|
||||
public static function valueOf(string $link): ?ResourceSite
|
||||
@@ -73,7 +65,7 @@ final class ResourceSite extends BaseEnum
|
||||
$parsedHost = parse_url($link, PHP_URL_HOST);
|
||||
|
||||
return Arr::first(
|
||||
ResourceSite::getInstances(),
|
||||
ResourceSite::cases(),
|
||||
fn (ResourceSite $site) => $parsedHost === ResourceSite::getDomain($site->value)
|
||||
);
|
||||
}
|
||||
@@ -88,13 +80,13 @@ final class ResourceSite extends BaseEnum
|
||||
{
|
||||
$site = ResourceSite::valueOf($link);
|
||||
|
||||
return match ($site?->value) {
|
||||
return match ($site) {
|
||||
ResourceSite::ANIDB,
|
||||
ResourceSite::ANILIST,
|
||||
ResourceSite::ANN,
|
||||
ResourceSite::MAL => Str::match('/\d+/', $link),
|
||||
ResourceSite::ANIME_PLANET => self::parseAnimePlanetIdFromLink($link),
|
||||
ResourceSite::KITSU => self::parseKitsuIdFromLink($link),
|
||||
ResourceSite::ANIME_PLANET => ResourceSite::parseAnimePlanetIdFromLink($link),
|
||||
ResourceSite::KITSU => ResourceSite::parseKitsuIdFromLink($link),
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
@@ -173,7 +165,7 @@ final class ResourceSite extends BaseEnum
|
||||
*/
|
||||
public function formatAnimeResourceLink(int $id, ?string $slug = null): ?string
|
||||
{
|
||||
return match ($this->value) {
|
||||
return match ($this) {
|
||||
ResourceSite::TWITTER => "https://twitter.com/$slug",
|
||||
ResourceSite::ANIDB => "https://anidb.net/anime/$id",
|
||||
ResourceSite::ANILIST => "https://anilist.co/anime/$id",
|
||||
@@ -194,7 +186,7 @@ final class ResourceSite extends BaseEnum
|
||||
*/
|
||||
public function formatArtistResourceLink(int $id, ?string $slug = null): ?string
|
||||
{
|
||||
return match ($this->value) {
|
||||
return match ($this) {
|
||||
ResourceSite::TWITTER => "https://twitter.com/$slug",
|
||||
ResourceSite::ANIDB => "https://anidb.net/creator/$id",
|
||||
ResourceSite::ANILIST => "https://anilist.co/staff/$id",
|
||||
@@ -214,7 +206,7 @@ final class ResourceSite extends BaseEnum
|
||||
*/
|
||||
public function formatStudioResourceLink(int $id, ?string $slug = null): ?string
|
||||
{
|
||||
return match ($this->value) {
|
||||
return match ($this) {
|
||||
ResourceSite::TWITTER => "https://twitter.com/$slug",
|
||||
ResourceSite::ANIDB => "https://anidb.net/creator/$id",
|
||||
ResourceSite::ANILIST => "https://anilist.co/studio/$id",
|
||||
|
||||
@@ -4,13 +4,15 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Enums\Models\Wiki;
|
||||
|
||||
use App\Enums\BaseEnum;
|
||||
use App\Concerns\Enums\LocalizesName;
|
||||
|
||||
/**
|
||||
* Class ThemeType.
|
||||
* Enum ThemeType.
|
||||
*/
|
||||
final class ThemeType extends BaseEnum
|
||||
enum ThemeType: int
|
||||
{
|
||||
public const OP = 0;
|
||||
public const ED = 1;
|
||||
use LocalizesName;
|
||||
|
||||
case OP = 0;
|
||||
case ED = 1;
|
||||
}
|
||||
|
||||
@@ -4,18 +4,18 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Enums\Models\Wiki;
|
||||
|
||||
use App\Enums\BaseEnum;
|
||||
use App\Concerns\Enums\CoercesInstances;
|
||||
use App\Concerns\Enums\LocalizesName;
|
||||
|
||||
/**
|
||||
* Class VideoOverlap.
|
||||
*
|
||||
* @method static static NONE()
|
||||
* @method static static TRANS()
|
||||
* @method static static OVER()
|
||||
* Enum VideoOverlap.
|
||||
*/
|
||||
final class VideoOverlap extends BaseEnum
|
||||
enum VideoOverlap: int
|
||||
{
|
||||
public const NONE = 0;
|
||||
public const TRANS = 1;
|
||||
public const OVER = 2;
|
||||
use CoercesInstances;
|
||||
use LocalizesName;
|
||||
|
||||
case NONE = 0;
|
||||
case TRANS = 1;
|
||||
case OVER = 2;
|
||||
}
|
||||
|
||||
@@ -4,36 +4,39 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Enums\Models\Wiki;
|
||||
|
||||
use App\Enums\BaseEnum;
|
||||
use App\Concerns\Enums\CoercesInstances;
|
||||
use App\Concerns\Enums\LocalizesName;
|
||||
|
||||
/**
|
||||
* Class VideoSource.
|
||||
* Enum VideoSource.
|
||||
*/
|
||||
final class VideoSource extends BaseEnum
|
||||
enum VideoSource: int
|
||||
{
|
||||
public const WEB = 0;
|
||||
public const RAW = 1;
|
||||
public const BD = 2;
|
||||
public const DVD = 3;
|
||||
public const VHS = 4;
|
||||
public const LD = 5;
|
||||
use CoercesInstances;
|
||||
use LocalizesName;
|
||||
|
||||
case WEB = 0;
|
||||
case RAW = 1;
|
||||
case BD = 2;
|
||||
case DVD = 3;
|
||||
case VHS = 4;
|
||||
case LD = 5;
|
||||
|
||||
/**
|
||||
* Score sources to help prioritize videos.
|
||||
* Note: This should be refactored into attributes.
|
||||
*
|
||||
* @param int|null $value
|
||||
* @return int
|
||||
*/
|
||||
public static function getPriority(?int $value): int
|
||||
public function getPriority(): int
|
||||
{
|
||||
return match ($value) {
|
||||
return match ($this) {
|
||||
self::BD => 60,
|
||||
self::DVD => 50,
|
||||
self::LD => 40,
|
||||
self::VHS => 30,
|
||||
self::WEB => 20,
|
||||
self::RAW => 10,
|
||||
default => 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,16 +4,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Enums\Rules;
|
||||
|
||||
use App\Enums\BaseEnum;
|
||||
|
||||
/**
|
||||
* Class ModerationService.
|
||||
*
|
||||
* @method static static NONE()
|
||||
* @method static static OPENAI()
|
||||
* Enum ModerationService.
|
||||
*/
|
||||
final class ModerationService extends BaseEnum
|
||||
enum ModerationService: string
|
||||
{
|
||||
public const NONE = 'none';
|
||||
public const OPENAI = 'openai';
|
||||
case NONE = 'none';
|
||||
case OPENAI = 'openai';
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class FeatureCreated extends FeatureEvent
|
||||
|
||||
return DiscordMessage::create('', [
|
||||
'description' => "Feature '**{$feature->getName()}**' has been created.",
|
||||
'color' => EmbedColor::GREEN,
|
||||
'color' => EmbedColor::GREEN->value,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class FeatureDeleted extends FeatureEvent
|
||||
|
||||
return DiscordMessage::create('', [
|
||||
'description' => "Feature '**{$feature->getName()}**' has been deleted.",
|
||||
'color' => EmbedColor::RED,
|
||||
'color' => EmbedColor::RED->value,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ class FeatureUpdated extends FeatureEvent
|
||||
return DiscordMessage::create('', [
|
||||
'description' => "Feature '**{$feature->getName()}**' has been updated.",
|
||||
'fields' => $this->getEmbedFields(),
|
||||
'color' => EmbedColor::YELLOW,
|
||||
'color' => EmbedColor::YELLOW->value,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class SettingCreated extends SettingEvent
|
||||
|
||||
return DiscordMessage::create('', [
|
||||
'description' => "Setting '**{$setting->getName()}**' has been created.",
|
||||
'color' => EmbedColor::GREEN,
|
||||
'color' => EmbedColor::GREEN->value,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class SettingDeleted extends SettingEvent
|
||||
|
||||
return DiscordMessage::create('', [
|
||||
'description' => "Setting '**{$setting->getName()}**' has been deleted.",
|
||||
'color' => EmbedColor::RED,
|
||||
'color' => EmbedColor::RED->value,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ class SettingUpdated extends SettingEvent
|
||||
return DiscordMessage::create('', [
|
||||
'description' => "Setting '**{$setting->getName()}**' has been updated.",
|
||||
'fields' => $this->getEmbedFields(),
|
||||
'color' => EmbedColor::YELLOW,
|
||||
'color' => EmbedColor::YELLOW->value,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class UserCreated extends UserEvent
|
||||
|
||||
return DiscordMessage::create('', [
|
||||
'description' => "User '**{$user->getName()}**' has been created.",
|
||||
'color' => EmbedColor::GREEN,
|
||||
'color' => EmbedColor::GREEN->value,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class UserDeleted extends UserEvent
|
||||
|
||||
return DiscordMessage::create('', [
|
||||
'description' => "User '**{$user->getName()}**' has been deleted.",
|
||||
'color' => EmbedColor::RED,
|
||||
'color' => EmbedColor::RED->value,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class UserRestored extends UserEvent
|
||||
|
||||
return DiscordMessage::create('', [
|
||||
'description' => "User '**{$user->getName()}**' has been restored.",
|
||||
'color' => EmbedColor::GREEN,
|
||||
'color' => EmbedColor::GREEN->value,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ class UserUpdated extends UserEvent
|
||||
return DiscordMessage::create('', [
|
||||
'description' => "User '**{$user->getName()}**' has been updated.",
|
||||
'fields' => $this->getEmbedFields(),
|
||||
'color' => EmbedColor::YELLOW,
|
||||
'color' => EmbedColor::YELLOW->value,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ abstract class BaseCreatedEvent extends BaseEvent implements DiscordMessageEvent
|
||||
{
|
||||
return DiscordMessage::create('', [
|
||||
'description' => $this->getDiscordMessageDescription(),
|
||||
'color' => EmbedColor::GREEN,
|
||||
'color' => EmbedColor::GREEN->value,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ abstract class BaseDeletedEvent extends BaseEvent implements DiscordMessageEvent
|
||||
{
|
||||
return DiscordMessage::create('', [
|
||||
'description' => $this->getDiscordMessageDescription(),
|
||||
'color' => EmbedColor::RED,
|
||||
'color' => EmbedColor::RED->value,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ abstract class BaseRestoredEvent extends BaseEvent implements DiscordMessageEven
|
||||
{
|
||||
return DiscordMessage::create('', [
|
||||
'description' => $this->getDiscordMessageDescription(),
|
||||
'color' => EmbedColor::GREEN,
|
||||
'color' => EmbedColor::GREEN->value,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ abstract class BaseUpdatedEvent extends BaseEvent implements DiscordMessageEvent
|
||||
return DiscordMessage::create('', [
|
||||
'description' => $this->getDiscordMessageDescription(),
|
||||
'fields' => $this->getEmbedFields(),
|
||||
'color' => EmbedColor::YELLOW,
|
||||
'color' => EmbedColor::YELLOW->value,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ abstract class PivotCreatedEvent extends BasePivotEvent
|
||||
{
|
||||
return DiscordMessage::create('', [
|
||||
'description' => $this->getDiscordMessageDescription(),
|
||||
'color' => EmbedColor::GREEN,
|
||||
'color' => EmbedColor::GREEN->value,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ abstract class PivotDeletedEvent extends BasePivotEvent
|
||||
{
|
||||
return DiscordMessage::create('', [
|
||||
'description' => $this->getDiscordMessageDescription(),
|
||||
'color' => EmbedColor::RED,
|
||||
'color' => EmbedColor::RED->value,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ abstract class PivotUpdatedEvent extends BasePivotEvent
|
||||
return DiscordMessage::create('', [
|
||||
'description' => $this->getDiscordMessageDescription(),
|
||||
'fields' => $this->getEmbedFields(),
|
||||
'color' => EmbedColor::YELLOW,
|
||||
'color' => EmbedColor::YELLOW->value,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ class AllowAudioStreams
|
||||
*/
|
||||
public function resolve(?User $user): bool
|
||||
{
|
||||
if (! empty($user?->can(SpecialPermission::BYPASS_FEATURE_FLAGS))) {
|
||||
if (! empty($user?->can(SpecialPermission::BYPASS_FEATURE_FLAGS->value))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ class AllowDumpDownloading
|
||||
*/
|
||||
public function resolve(?User $user): bool
|
||||
{
|
||||
if (! empty($user?->can(SpecialPermission::BYPASS_FEATURE_FLAGS))) {
|
||||
if (! empty($user?->can(SpecialPermission::BYPASS_FEATURE_FLAGS->value))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ class AllowPlaylistManagement
|
||||
*/
|
||||
public function resolve(?User $user): bool
|
||||
{
|
||||
if (! empty($user?->can(SpecialPermission::BYPASS_FEATURE_FLAGS))) {
|
||||
if (! empty($user?->can(SpecialPermission::BYPASS_FEATURE_FLAGS->value))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ class AllowScriptDownloading
|
||||
*/
|
||||
public function resolve(?User $user): bool
|
||||
{
|
||||
if (! empty($user?->can(SpecialPermission::BYPASS_FEATURE_FLAGS))) {
|
||||
if (! empty($user?->can(SpecialPermission::BYPASS_FEATURE_FLAGS->value))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ class AllowVideoStreams
|
||||
*/
|
||||
public function resolve(?User $user): bool
|
||||
{
|
||||
if (! empty($user?->can(SpecialPermission::BYPASS_FEATURE_FLAGS))) {
|
||||
if (! empty($user?->can(SpecialPermission::BYPASS_FEATURE_FLAGS->value))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,9 +12,7 @@ use App\Http\Api\Query\Query;
|
||||
use App\Http\Api\Schema\Schema;
|
||||
use App\Http\Api\Scope\Scope;
|
||||
use App\Http\Api\Scope\ScopeParser;
|
||||
use BenSampo\Enum\Exceptions\InvalidEnumKeyException;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
@@ -66,21 +64,18 @@ class HasCriteria extends Criteria
|
||||
public static function make(Scope $scope, string $filterParam, mixed $filterValues): static
|
||||
{
|
||||
$field = '';
|
||||
$comparisonOperator = ComparisonOperator::GTE();
|
||||
$comparisonOperator = ComparisonOperator::GTE;
|
||||
$count = 1;
|
||||
$logicalOperator = BinaryLogicalOperator::AND();
|
||||
$logicalOperator = BinaryLogicalOperator::AND;
|
||||
|
||||
$filterParts = Str::of($filterParam)->explode(Criteria::PARAM_SEPARATOR);
|
||||
|
||||
while ($filterParts->isNotEmpty()) {
|
||||
$filterPart = $filterParts->pop();
|
||||
|
||||
// Set logical operator
|
||||
if (empty($field) && BinaryLogicalOperator::hasKey(Str::upper($filterPart))) {
|
||||
try {
|
||||
$logicalOperator = BinaryLogicalOperator::fromKey(Str::upper($filterPart));
|
||||
} catch (InvalidEnumKeyException $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
if (empty($field) && BinaryLogicalOperator::unstrictCoerce($filterPart) !== null) {
|
||||
$logicalOperator = BinaryLogicalOperator::unstrictCoerce($filterPart);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -94,12 +89,8 @@ class HasCriteria extends Criteria
|
||||
}
|
||||
|
||||
// Set comparison operator
|
||||
if (empty($field) && ComparisonOperator::hasKey(Str::upper($filterPart))) {
|
||||
try {
|
||||
$comparisonOperator = ComparisonOperator::fromKey(Str::upper($filterPart));
|
||||
} catch (InvalidEnumKeyException $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
if (empty($field) && ComparisonOperator::unstrictCoerce($filterPart) !== null) {
|
||||
$comparisonOperator = ComparisonOperator::unstrictCoerce($filterPart);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ class TrashedCriteria extends Criteria
|
||||
|
||||
return new static(
|
||||
new Predicate(TrashedCriteria::PARAM_VALUE, null, $expression),
|
||||
BinaryLogicalOperator::AND(),
|
||||
BinaryLogicalOperator::AND,
|
||||
$scope
|
||||
);
|
||||
}
|
||||
@@ -69,9 +69,9 @@ class TrashedCriteria extends Criteria
|
||||
|
||||
foreach ($filterValues as $filterValue) {
|
||||
$builder = match (Str::lower($filterValue)) {
|
||||
TrashedStatus::WITH => $builder->withTrashed(),
|
||||
TrashedStatus::WITHOUT => $builder->withoutTrashed(),
|
||||
TrashedStatus::ONLY => $builder->onlyTrashed(),
|
||||
TrashedStatus::WITH->value => $builder->withTrashed(),
|
||||
TrashedStatus::WITHOUT->value => $builder->withoutTrashed(),
|
||||
TrashedStatus::ONLY->value => $builder->onlyTrashed(),
|
||||
default => $builder,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -11,10 +11,8 @@ use App\Http\Api\Filter\Filter;
|
||||
use App\Http\Api\Query\Query;
|
||||
use App\Http\Api\Schema\Schema;
|
||||
use App\Http\Api\Scope\Scope;
|
||||
use BenSampo\Enum\Exceptions\InvalidEnumKeyException;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
@@ -48,30 +46,22 @@ class WhereCriteria extends Criteria
|
||||
public static function make(Scope $scope, string $filterParam, mixed $filterValues): static
|
||||
{
|
||||
$field = '';
|
||||
$comparisonOperator = ComparisonOperator::EQ();
|
||||
$logicalOperator = BinaryLogicalOperator::AND();
|
||||
$comparisonOperator = ComparisonOperator::EQ;
|
||||
$logicalOperator = BinaryLogicalOperator::AND;
|
||||
|
||||
$filterParts = Str::of($filterParam)->explode(Criteria::PARAM_SEPARATOR);
|
||||
while ($filterParts->isNotEmpty()) {
|
||||
$filterPart = $filterParts->pop();
|
||||
|
||||
// Set logical operator
|
||||
if (empty($field) && BinaryLogicalOperator::hasKey(Str::upper($filterPart))) {
|
||||
try {
|
||||
$logicalOperator = BinaryLogicalOperator::fromKey(Str::upper($filterPart));
|
||||
} catch (InvalidEnumKeyException $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
if (empty($field) && BinaryLogicalOperator::unstrictCoerce($filterPart) !== null) {
|
||||
$logicalOperator = BinaryLogicalOperator::unstrictCoerce($filterPart);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Set comparison operator
|
||||
if (empty($field) && ComparisonOperator::hasKey(Str::upper($filterPart))) {
|
||||
try {
|
||||
$comparisonOperator = ComparisonOperator::fromKey(Str::upper($filterPart));
|
||||
} catch (InvalidEnumKeyException $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
if (empty($field) && ComparisonOperator::unstrictCoerce($filterPart) !== null) {
|
||||
$comparisonOperator = ComparisonOperator::unstrictCoerce($filterPart);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -105,7 +95,7 @@ class WhereCriteria extends Criteria
|
||||
? $builder->qualifyColumn($filter->getColumn())
|
||||
: $filter->getColumn();
|
||||
|
||||
return match ($filter->clause()->value) {
|
||||
return match ($filter->clause()) {
|
||||
Clause::WHERE => $builder->where(
|
||||
$column,
|
||||
$this->getComparisonOperator()?->value,
|
||||
@@ -118,7 +108,6 @@ class WhereCriteria extends Criteria
|
||||
Arr::first($filter->getFilterValues($this->getFilterValues())),
|
||||
$this->getLogicalOperator()->value
|
||||
),
|
||||
default => $builder,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,7 @@ use App\Http\Api\Filter\Filter;
|
||||
use App\Http\Api\Query\Query;
|
||||
use App\Http\Api\Schema\Schema;
|
||||
use App\Http\Api\Scope\Scope;
|
||||
use BenSampo\Enum\Exceptions\InvalidEnumKeyException;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Str;
|
||||
use RuntimeException;
|
||||
|
||||
@@ -60,7 +58,7 @@ class WhereInCriteria extends Criteria
|
||||
public static function make(Scope $scope, string $filterParam, mixed $filterValues): static
|
||||
{
|
||||
$field = '';
|
||||
$operator = BinaryLogicalOperator::AND();
|
||||
$operator = BinaryLogicalOperator::AND;
|
||||
$not = false;
|
||||
|
||||
$filterParts = Str::of($filterParam)->explode(Criteria::PARAM_SEPARATOR);
|
||||
@@ -68,18 +66,14 @@ class WhereInCriteria extends Criteria
|
||||
$filterPart = $filterParts->pop();
|
||||
|
||||
// Set Not
|
||||
if (empty($field) && UnaryLogicalOperator::hasKey(Str::upper($filterPart))) {
|
||||
if (empty($field) && UnaryLogicalOperator::unstrictCoerce($filterPart) !== null) {
|
||||
$not = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Set operator
|
||||
if (empty($field) && BinaryLogicalOperator::hasKey(Str::upper($filterPart))) {
|
||||
try {
|
||||
$operator = BinaryLogicalOperator::fromKey(Str::upper($filterPart));
|
||||
} catch (InvalidEnumKeyException $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
if (empty($field) && BinaryLogicalOperator::unstrictCoerce($filterPart) !== null) {
|
||||
$operator = BinaryLogicalOperator::unstrictCoerce($filterPart);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -114,7 +108,7 @@ class WhereInCriteria extends Criteria
|
||||
? $builder->qualifyColumn($filter->getColumn())
|
||||
: $filter->getColumn();
|
||||
|
||||
return match ($filter->clause()->value) {
|
||||
return match ($filter->clause()) {
|
||||
Clause::WHERE => $builder->whereIn(
|
||||
$column,
|
||||
$filter->getFilterValues($this->getFilterValues()),
|
||||
@@ -122,7 +116,6 @@ class WhereInCriteria extends Criteria
|
||||
$this->not()
|
||||
),
|
||||
Clause::HAVING => throw new RuntimeException('IN operator is not supported in HAVING clause'),
|
||||
default => $builder
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ class LimitCriteria extends Criteria
|
||||
*/
|
||||
public function getStrategy(): PaginationStrategy
|
||||
{
|
||||
return PaginationStrategy::LIMIT();
|
||||
return PaginationStrategy::LIMIT;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,7 +29,7 @@ class OffsetCriteria extends Criteria
|
||||
*/
|
||||
public function getStrategy(): PaginationStrategy
|
||||
{
|
||||
return PaginationStrategy::OFFSET();
|
||||
return PaginationStrategy::OFFSET;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,10 +36,12 @@ class FeaturedThemeEndAtField extends DateField implements CreatableField, Updat
|
||||
*/
|
||||
public function getCreationRules(Request $request): array
|
||||
{
|
||||
$allowedDateFormats = array_column(AllowedDateFormat::cases(), 'value');
|
||||
|
||||
return [
|
||||
'required',
|
||||
Str::of('date_format:')
|
||||
->append(implode(',', AllowedDateFormat::getValues()))
|
||||
->append(implode(',', $allowedDateFormats))
|
||||
->__toString(),
|
||||
Str::of('after:')
|
||||
->append($this->resolveStartAt($request))
|
||||
@@ -55,11 +57,13 @@ class FeaturedThemeEndAtField extends DateField implements CreatableField, Updat
|
||||
*/
|
||||
public function getUpdateRules(Request $request): array
|
||||
{
|
||||
$allowedDateFormats = array_column(AllowedDateFormat::cases(), 'value');
|
||||
|
||||
return [
|
||||
'sometimes',
|
||||
'required',
|
||||
Str::of('date_format:')
|
||||
->append(implode(',', AllowedDateFormat::getValues()))
|
||||
->append(implode(',', $allowedDateFormats))
|
||||
->__toString(),
|
||||
Str::of('after:')
|
||||
->append($this->resolveStartAt($request))
|
||||
@@ -82,6 +86,6 @@ class FeaturedThemeEndAtField extends DateField implements CreatableField, Updat
|
||||
/** @var FeaturedTheme|null $featuredTheme */
|
||||
$featuredTheme = $request->route('featuredtheme');
|
||||
|
||||
return $featuredTheme?->start_at?->format(AllowedDateFormat::YMDHISU);
|
||||
return $featuredTheme?->start_at?->format(AllowedDateFormat::YMDHISU->value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,10 +36,12 @@ class FeaturedThemeStartAtField extends DateField implements CreatableField, Upd
|
||||
*/
|
||||
public function getCreationRules(Request $request): array
|
||||
{
|
||||
$allowedDateFormats = array_column(AllowedDateFormat::cases(), 'value');
|
||||
|
||||
return [
|
||||
'required',
|
||||
Str::of('date_format:')
|
||||
->append(implode(',', AllowedDateFormat::getValues()))
|
||||
->append(implode(',', $allowedDateFormats))
|
||||
->__toString(),
|
||||
Str::of('before:')
|
||||
->append($this->resolveEndAt($request))
|
||||
@@ -55,11 +57,13 @@ class FeaturedThemeStartAtField extends DateField implements CreatableField, Upd
|
||||
*/
|
||||
public function getUpdateRules(Request $request): array
|
||||
{
|
||||
$allowedDateFormats = array_column(AllowedDateFormat::cases(), 'value');
|
||||
|
||||
return [
|
||||
'sometimes',
|
||||
'required',
|
||||
Str::of('date_format:')
|
||||
->append(implode(',', AllowedDateFormat::getValues()))
|
||||
->append(implode(',', $allowedDateFormats))
|
||||
->__toString(),
|
||||
Str::of('before:')
|
||||
->append($this->resolveEndAt($request))
|
||||
@@ -82,6 +86,6 @@ class FeaturedThemeStartAtField extends DateField implements CreatableField, Upd
|
||||
/** @var FeaturedTheme|null $featuredTheme */
|
||||
$featuredTheme = $request->route('featuredtheme');
|
||||
|
||||
return $featuredTheme?->end_at?->format(AllowedDateFormat::YMDHISU);
|
||||
return $featuredTheme?->end_at?->format(AllowedDateFormat::YMDHISU->value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ abstract class AggregateField extends Field implements FilterableField, Renderab
|
||||
*/
|
||||
public function getSort(): Sort
|
||||
{
|
||||
return new Sort(key: $this->alias(), qualifyColumn: QualifyColumn::NO());
|
||||
return new Sort(key: $this->alias(), qualifyColumn: QualifyColumn::NO);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,7 +24,7 @@ abstract class CountField extends AggregateField
|
||||
*/
|
||||
public function __construct(Schema $schema, string $relation)
|
||||
{
|
||||
parent::__construct($schema, $relation, AggregateFunction::COUNT(), '*');
|
||||
parent::__construct($schema, $relation, AggregateFunction::COUNT, '*');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,6 +34,6 @@ abstract class CountField extends AggregateField
|
||||
*/
|
||||
public function getFilter(): Filter
|
||||
{
|
||||
return new IntFilter(key: $this->alias(), qualifyColumn: QualifyColumn::NO(), clause: Clause::HAVING());
|
||||
return new IntFilter(key: $this->alias(), qualifyColumn: QualifyColumn::NO, clause: Clause::HAVING);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ abstract class ExistsField extends AggregateField
|
||||
*/
|
||||
public function __construct(Schema $schema, string $relation)
|
||||
{
|
||||
parent::__construct($schema, $relation, AggregateFunction::EXISTS(), '*');
|
||||
parent::__construct($schema, $relation, AggregateFunction::EXISTS, '*');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,6 +34,6 @@ abstract class ExistsField extends AggregateField
|
||||
*/
|
||||
public function getFilter(): Filter
|
||||
{
|
||||
return new BooleanFilter(key: $this->alias(), qualifyColumn: QualifyColumn::NO(), clause: Clause::HAVING());
|
||||
return new BooleanFilter(key: $this->alias(), qualifyColumn: QualifyColumn::NO, clause: Clause::HAVING);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ class BalanceDateField extends DateField implements CreatableField, UpdatableFie
|
||||
{
|
||||
return [
|
||||
'required',
|
||||
Str::of('date_format:')->append(AllowedDateFormat::YMD)->__toString(),
|
||||
Str::of('date_format:')->append(AllowedDateFormat::YMD->value)->__toString(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class BalanceDateField extends DateField implements CreatableField, UpdatableFie
|
||||
return [
|
||||
'sometimes',
|
||||
'required',
|
||||
Str::of('date_format:')->append(AllowedDateFormat::YMD)->__toString(),
|
||||
Str::of('date_format:')->append(AllowedDateFormat::YMD->value)->__toString(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ use App\Enums\Models\Billing\BalanceFrequency;
|
||||
use App\Http\Api\Field\EnumField;
|
||||
use App\Http\Api\Schema\Schema;
|
||||
use App\Models\Billing\Balance;
|
||||
use BenSampo\Enum\Rules\EnumValue;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rules\Enum;
|
||||
|
||||
/**
|
||||
* Class BalanceFrequencyField.
|
||||
@@ -38,7 +38,7 @@ class BalanceFrequencyField extends EnumField implements CreatableField, Updatab
|
||||
{
|
||||
return [
|
||||
'required',
|
||||
new EnumValue(BalanceFrequency::class),
|
||||
new Enum(BalanceFrequency::class),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class BalanceFrequencyField extends EnumField implements CreatableField, Updatab
|
||||
return [
|
||||
'sometimes',
|
||||
'required',
|
||||
new EnumValue(BalanceFrequency::class),
|
||||
new Enum(BalanceFrequency::class),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user