-
Notifications
You must be signed in to change notification settings - Fork 8
Implemented doctrine enums #339
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
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
cb41c45
implemented doctrine enums
MarioRadu 09aafa3
run git stash command
MarioRadu 50eccad
renamed enums to match the ones from 5.0 branch
MarioRadu 43d5d99
added fresh migration
MarioRadu 9821c2a
added fresh migration
MarioRadu 5bc9937
bug fixes for enums
MarioRadu b422534
bug fixes for enums
MarioRadu 3a1c032
bug fixes for enums
MarioRadu bd56d03
fonts fix
MarioRadu d828225
tests bug fix
MarioRadu 8f59cac
tests bug fix
MarioRadu 8bb88bb
tests bug fix
MarioRadu b58f2b0
tests bug fix
MarioRadu b531022
tests bug fix
MarioRadu 21c110e
tests bug fix
MarioRadu 9278f37
tests bug fix
MarioRadu ad2ef92
tests bug fix
MarioRadu 6a7584f
phpcs fix
MarioRadu 34140c0
phpcs fix
MarioRadu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Admin\Admin\DBAL\Types; | ||
|
|
||
| use Admin\Admin\Enum\AdminRoleEnum; | ||
| use Admin\App\DBAL\Types\AbstractEnumType; | ||
|
|
||
| class AdminRoleEnumType extends AbstractEnumType | ||
| { | ||
| public const NAME = 'admin_role_enum'; | ||
|
|
||
| protected function getEnumClass(): string | ||
| { | ||
| return AdminRoleEnum::class; | ||
| } | ||
|
|
||
| public function getName(): string | ||
| { | ||
| return self::NAME; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Admin\Admin\DBAL\Types; | ||
|
|
||
| use Admin\Admin\Enum\AdminStatusEnum; | ||
| use Admin\App\DBAL\Types\AbstractEnumType; | ||
|
|
||
| class AdminStatusEnumType extends AbstractEnumType | ||
| { | ||
| public const NAME = 'admin_status_enum'; | ||
|
|
||
| protected function getEnumClass(): string | ||
| { | ||
| return AdminStatusEnum::class; | ||
| } | ||
|
|
||
| public function getName(): string | ||
| { | ||
| return self::NAME; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Admin\Admin\DBAL\Types; | ||
|
|
||
| use Admin\Admin\Enum\SuccessFailureEnum; | ||
| use Admin\App\DBAL\Types\AbstractEnumType; | ||
|
|
||
| class SuccessFailureEnumType extends AbstractEnumType | ||
| { | ||
| public const NAME = 'success_failure_enum'; | ||
|
|
||
| protected function getEnumClass(): string | ||
| { | ||
| return SuccessFailureEnum::class; | ||
| } | ||
|
|
||
| public function getName(): string | ||
| { | ||
| return self::NAME; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Admin\Admin\DBAL\Types; | ||
|
|
||
| use Admin\Admin\Enum\YesNoEnum; | ||
| use Admin\App\DBAL\Types\AbstractEnumType; | ||
|
|
||
| class YesNoEnumType extends AbstractEnumType | ||
| { | ||
| public const NAME = 'yes_no_enum'; | ||
|
|
||
| protected function getEnumClass(): string | ||
| { | ||
| return YesNoEnum::class; | ||
| } | ||
|
|
||
| public function getName(): string | ||
| { | ||
| return self::NAME; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
|
|
||
| namespace Admin\Admin\Entity; | ||
|
|
||
| use Admin\Admin\Enum\AdminStatusEnum; | ||
| use Admin\Admin\Repository\AdminRepository; | ||
| use Admin\App\Entity\AbstractEntity; | ||
| use Admin\App\Entity\TimestampsTrait; | ||
|
|
@@ -16,48 +17,39 @@ | |
| use function password_verify; | ||
|
|
||
| #[ORM\Entity(repositoryClass: AdminRepository::class)] | ||
| #[ORM\Table(name: "admin")] | ||
| #[ORM\Table(name: 'admin')] | ||
| #[ORM\HasLifecycleCallbacks] | ||
| #[ORM\Cache(usage: "NONSTRICT_READ_WRITE")] | ||
| #[ORM\Cache(usage: 'NONSTRICT_READ_WRITE')] | ||
| class Admin extends AbstractEntity implements AdminInterface | ||
| { | ||
| use TimestampsTrait; | ||
|
|
||
| public const STATUS_ACTIVE = 'active'; | ||
| public const STATUS_INACTIVE = 'pending'; | ||
| public const STATUSES = [ | ||
| self::STATUS_ACTIVE, | ||
| self::STATUS_INACTIVE, | ||
| ]; | ||
|
|
||
| #[ORM\Column(name: "identity", type: "string", length: 100, unique: true)] | ||
| #[ORM\Column(name: 'identity', type: 'string', length: 100, unique: true)] | ||
| protected string $identity; | ||
|
|
||
| #[ORM\Column(name: "firstName", type: "string", length: 255, nullable: true)] | ||
| #[ORM\Column(name: 'firstName', type: 'string', length: 255, nullable: true)] | ||
| protected ?string $firstName = null; | ||
|
|
||
| #[ORM\Column(name: "lastName", type: "string", length: 255, nullable: true)] | ||
| #[ORM\Column(name: 'lastName', type: 'string', length: 255, nullable: true)] | ||
| protected ?string $lastName = null; | ||
|
|
||
| #[ORM\Column(name: "password", type: "string", length: 100)] | ||
| #[ORM\Column(name: 'password', type: 'string', length: 100)] | ||
| protected string $password; | ||
|
|
||
| #[ORM\Column( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #[ORM\Column(type: 'admin_status_enum', options: ['default' => AdminStatusEnum::Active])] |
||
| name: "status", | ||
| type: "string", | ||
| length: 20, | ||
| nullable: false, | ||
| columnDefinition: "ENUM('pending', 'active')" | ||
| type: 'admin_status_enum', | ||
| enumType: AdminStatusEnum::class, | ||
| options: ['default' => AdminStatusEnum::Active] | ||
| )] | ||
| protected string $status = self::STATUS_ACTIVE; | ||
| protected AdminStatusEnum $status = AdminStatusEnum::Active; | ||
|
|
||
| #[ORM\ManyToMany(targetEntity: AdminRole::class, fetch: "EAGER")] | ||
| #[ORM\JoinTable(name: "admin_roles")] | ||
| #[ORM\JoinColumn(name: "userUuid", referencedColumnName: "uuid")] | ||
| #[ORM\InverseJoinColumn(name: "roleUuid", referencedColumnName: "uuid")] | ||
| #[ORM\ManyToMany(targetEntity: AdminRole::class, fetch: 'EAGER')] | ||
| #[ORM\JoinTable(name: 'admin_roles')] | ||
| #[ORM\JoinColumn(name: 'userUuid', referencedColumnName: 'uuid')] | ||
| #[ORM\InverseJoinColumn(name: 'roleUuid', referencedColumnName: 'uuid')] | ||
| protected Collection $roles; | ||
|
|
||
| #[ORM\OneToMany(mappedBy: 'admin', targetEntity: Setting::class)] | ||
| #[ORM\OneToMany(targetEntity: Setting::class, mappedBy: 'admin')] | ||
| protected Collection $settings; | ||
|
|
||
| public function __construct() | ||
|
|
@@ -75,7 +67,7 @@ public function getArrayCopy(): array | |
| 'identity' => $this->getIdentity(), | ||
| 'firstName' => $this->getfirstName(), | ||
| 'lastName' => $this->getlastName(), | ||
| 'status' => $this->getStatus(), | ||
| 'status' => $this->getStatus()->value, | ||
| 'roles' => array_map(function (AdminRole $role) { | ||
| return $role->getArrayCopy(); | ||
| }, $this->getRoles()), | ||
|
|
@@ -137,12 +129,12 @@ public function verifyPassword(string $password): bool | |
| return password_verify($password, $this->getPassword()); | ||
| } | ||
|
|
||
| public function getStatus(): string | ||
| public function getStatus(): AdminStatusEnum | ||
| { | ||
| return $this->status; | ||
| } | ||
|
|
||
| public function setStatus(string $status): self | ||
| public function setStatus(AdminStatusEnum $status): self | ||
| { | ||
| $this->status = $status; | ||
|
|
||
|
|
@@ -183,4 +175,9 @@ public function removeRole(AdminRole $role): AdminInterface | |
|
|
||
| return $this; | ||
| } | ||
|
|
||
| public function isActive(): bool | ||
| { | ||
| return $this->getStatus() === AdminStatusEnum::Active; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot force
->valueon$methodNamebecause this can be a getter on any property from theidentity_class. We can still check status as long as we use the enum in the option value. See below example:config/autoload/authentication.global.php: