Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Replace elao/enum with native PHP enums #288

Merged
merged 1 commit into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"minimum-stability": "stable",
"prefer-stable": true,
"require": {
"php": ">=8.1",
"php": ">=8.2",
"ext-ctype": "*",
"ext-dom": "*",
"ext-iconv": "*",
Expand All @@ -14,7 +14,6 @@
"doctrine/doctrine-fixtures-bundle": "^3.4",
"doctrine/doctrine-migrations-bundle": "^3.2",
"doctrine/orm": "^2.16",
"elao/enum": "^1.7",
"erusev/parsedown": "^1.7",
"friendsofsymfony/jsrouting-bundle": "^3.3",
"knpuniversity/oauth2-client-bundle": "^2.15",
Expand Down
113 changes: 11 additions & 102 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true],
KnpU\OAuth2ClientBundle\KnpUOAuth2ClientBundle::class => ['all' => true],
Elao\Enum\Bridge\Symfony\Bundle\ElaoEnumBundle::class => ['all' => true],
FOS\JsRoutingBundle\FOSJsRoutingBundle::class => ['all' => true],
Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true],
ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true],
Expand Down
2 changes: 1 addition & 1 deletion config/doctrine/Mod/AbstractMod.orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<entity name="App\Entity\Mod\AbstractMod" table="mods" repository-class="App\Repository\Mod\ModRepository" inheritance-type="SINGLE_TABLE">
<field name="name" type="string" length="255"/>
<field name="description" type="string" length="255" nullable="true"/>
<field name="status" type="mod_status_enum" length="255" nullable="true"/>
<field name="status" enum-type="App\Entity\Mod\Enum\ModStatusEnum" nullable="true"/>

<discriminator-column name="source" type="string" length="255"/>
<discriminator-map>
Expand Down
2 changes: 1 addition & 1 deletion config/doctrine/Mod/SteamWorkshopMod.orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

<entity name="App\Entity\Mod\SteamWorkshopMod" repository-class="App\Repository\Mod\SteamWorkshopModRepository">
<field name="type" type="mod_type_enum" length="255"/>
<field name="type" enum-type="App\Entity\Mod\Enum\ModTypeEnum"/>
<field name="itemId" type="bigint" unique="true"/>
</entity>

Expand Down
11 changes: 0 additions & 11 deletions config/packages/elao_enum.yaml

This file was deleted.

31 changes: 31 additions & 0 deletions migrations/Version20230827120512.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20230827120512 extends AbstractMigration
{
public function getDescription(): string
{
return 'Replace elao/enum with native PHP enums. Remove Doctrine enum type comments';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE mods CHANGE status status VARCHAR(255) DEFAULT NULL, CHANGE type type VARCHAR(255) DEFAULT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE mods CHANGE type type VARCHAR(255) DEFAULT NULL COMMENT \'(DC2Type:mod_type_enum)\', CHANGE status status VARCHAR(255) DEFAULT NULL COMMENT \'(DC2Type:mod_status_enum)\'');
}
}
13 changes: 5 additions & 8 deletions src/Api/DataTransformer/Mod/ModOutputDataTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,17 @@ public function transform($object, string $to, array $context = []): ModOutput

$output->setId($object->getId()->toString());
$output->setName($object->getName());
$output->setStatus($object->getStatus()?->value);
$output->setCreatedAt($object->getCreatedAt());
$output->setLastUpdatedAt($object->getLastUpdatedAt());

/** @var null|string $status */
$status = $object->getStatus() ? $object->getStatus()->getValue() : null;
$output->setStatus($status);

if ($object instanceof SteamWorkshopMod) {
$output->setType($object->getType()->getValue());
$output->setSource(ModSourceEnum::STEAM_WORKSHOP);
$output->setType($object->getType()->value);
$output->setSource(ModSourceEnum::STEAM_WORKSHOP->value);
$output->setItemId($object->getItemId());
} elseif ($object instanceof DirectoryMod) {
$output->setType(ModTypeEnum::SERVER_SIDE);
$output->setSource(ModSourceEnum::DIRECTORY);
$output->setType(ModTypeEnum::SERVER_SIDE->value);
$output->setSource(ModSourceEnum::DIRECTORY->value);
$output->setDirectory($object->getDirectory());
}

Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Dlc/CreateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(
}

#[Route('/dlc/create', name: 'app_dlc_create')]
#[IsGranted(PermissionsEnum::DLC_CREATE)]
#[IsGranted(PermissionsEnum::DLC_CREATE->value)]
public function __invoke(Request $request): Response
{
$dlcFormDto = new DlcFormDto();
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Dlc/DeleteAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(
}

#[Route('/dlc/{id}/delete', name: 'app_dlc_delete')]
#[IsGranted(PermissionsEnum::DLC_DELETE, 'dlc')]
#[IsGranted(PermissionsEnum::DLC_DELETE->value, 'dlc')]
public function __invoke(Dlc $dlc): Response
{
$this->entityManager->remove($dlc);
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Dlc/ListAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(
}

#[Route('/dlc/list', name: 'app_dlc_list')]
#[IsGranted(PermissionsEnum::DLC_LIST)]
#[IsGranted(PermissionsEnum::DLC_LIST->value)]
public function __invoke(): Response
{
$dlcs = $this->dlcRepository->findBy([], ['name' => 'ASC']);
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Dlc/UpdateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct(
}

#[Route('/dlc/{id}/update', name: 'app_dlc_update')]
#[IsGranted(PermissionsEnum::DLC_UPDATE, 'dlc')]
#[IsGranted(PermissionsEnum::DLC_UPDATE->value, 'dlc')]
public function __invoke(Request $request, Dlc $dlc): Response
{
$dlcFormDto = $this->dataTransformerRegistry->transformFromEntity(new DlcFormDto(), $dlc);
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Mod/CreateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(
}

#[Route('/mod/create', name: 'app_mod_create')]
#[IsGranted(PermissionsEnum::MOD_CREATE)]
#[IsGranted(PermissionsEnum::MOD_CREATE->value)]
public function __invoke(Request $request): Response
{
$modFormDto = new ModFormDto();
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Mod/DeleteAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(
}

#[Route('/mod/{id}/delete', name: 'app_mod_delete')]
#[IsGranted(PermissionsEnum::MOD_DELETE, 'mod')]
#[IsGranted(PermissionsEnum::MOD_DELETE->value, 'mod')]
public function __invoke(AbstractMod $mod): Response
{
$this->entityManager->remove($mod);
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Mod/ListAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(
}

#[Route('/mod/list', name: 'app_mod_list')]
#[IsGranted(PermissionsEnum::MOD_LIST)]
#[IsGranted(PermissionsEnum::MOD_LIST->value)]
public function __invoke(): Response
{
$mods = $this->modRepository->findBy([], ['name' => 'ASC']);
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Mod/UpdateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct(
}

#[Route('/mod/{id}/update', name: 'app_mod_update')]
#[IsGranted(PermissionsEnum::MOD_UPDATE, 'mod')]
#[IsGranted(PermissionsEnum::MOD_UPDATE->value, 'mod')]
public function __invoke(Request $request, AbstractMod $mod): Response
{
$modFormDto = $this->dataTransformerRegistry->transformFromEntity(new ModFormDto(), $mod);
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/ModGroup/CreateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(
}

#[Route('/mod-group/create', name: 'app_mod_group_create')]
#[IsGranted(PermissionsEnum::MOD_GROUP_CREATE)]
#[IsGranted(PermissionsEnum::MOD_GROUP_CREATE->value)]
public function __invoke(Request $request): Response
{
$modGroupFormDto = new ModGroupFormDto();
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/ModGroup/DeleteAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(
}

#[Route('/mod-group/{name}/delete', name: 'app_mod_group_delete')]
#[IsGranted(PermissionsEnum::MOD_GROUP_DELETE, 'modGroup')]
#[IsGranted(PermissionsEnum::MOD_GROUP_DELETE->value, 'modGroup')]
public function __invoke(ModGroup $modGroup): Response
{
$this->entityManager->remove($modGroup);
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/ModGroup/ListAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(
}

#[Route('/mod-group/list', name: 'app_mod_group_list')]
#[IsGranted(PermissionsEnum::MOD_GROUP_LIST)]
#[IsGranted(PermissionsEnum::MOD_GROUP_LIST->value)]
public function __invoke(): Response
{
$modGroups = $this->modGroupRepository->findBy([], ['name' => 'ASC']);
Expand Down
Loading
Loading