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

Add enum support #734

Merged
merged 24 commits into from
Jul 28, 2024
Merged

Add enum support #734

merged 24 commits into from
Jul 28, 2024

Conversation

samdark
Copy link
Member

@samdark samdark commented Jul 26, 2024

Q A
Is bugfix?
New feature? ✔️
Breaks BC? ?
enum PostStatus: string
{
    case DRAFT = 'draft';
    case PUBLISHED = 'published';
}

class Post
{

    public function __construct(
        #[\Yiisoft\Validator\Rule\In(PostStatus::class)]
        private string $status
    )
    {
    }
}

@samdark samdark requested a review from a team July 26, 2024 11:24
@samdark samdark marked this pull request as draft July 26, 2024 11:24
@samdark samdark added the type:enhancement Enhancement label Jul 26, 2024
@samdark
Copy link
Member Author

samdark commented Jul 26, 2024

Consider #[EnumValue(PostStatus::class)] instead of #In(PostStatus::class)].

@samdark
Copy link
Member Author

samdark commented Jul 26, 2024

Also need to cover new code with tests.

@samdark
Copy link
Member Author

samdark commented Jul 26, 2024

Likely need an ability to verify against names and non-backed enums.

@samdark
Copy link
Member Author

samdark commented Jul 26, 2024

#[InEnum(PostStatus::class)]. Could also set names: true to force using names for backed enums. For non-backend ones, names will be used.

@samdark samdark changed the title Add backend enum support to In() rule Add enum support Jul 26, 2024
@samdark samdark changed the base branch from 1.x to master July 26, 2024 20:57
@samdark samdark added this to the 2.0 milestone Jul 27, 2024
@samdark samdark marked this pull request as ready for review July 27, 2024 08:02
tests/Rule/InEnumTest.php Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
src/Rule/InEnum.php Outdated Show resolved Hide resolved
src/Rule/InEnumHandler.php Outdated Show resolved Hide resolved
src/Rule/InEnum.php Outdated Show resolved Hide resolved
src/Rule/InEnum.php Outdated Show resolved Hide resolved
src/Rule/InEnum.php Outdated Show resolved Hide resolved
src/Rule/InEnum.php Outdated Show resolved Hide resolved
src/Rule/InEnum.php Show resolved Hide resolved
@samdark samdark requested a review from vjik July 28, 2024 13:16
CHANGELOG.md Outdated Show resolved Hide resolved
src/Rule/InEnum.php Outdated Show resolved Hide resolved
src/Rule/InEnumHandler.php Show resolved Hide resolved
samdark and others added 3 commits July 28, 2024 18:00
@vjik vjik merged commit d7896c3 into master Jul 28, 2024
24 of 25 checks passed
@vjik vjik deleted the add-enum-to-in branch July 28, 2024 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:enhancement Enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants