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 support for when; #22

Merged
merged 1 commit into from
Nov 19, 2024
Merged

Conversation

zero-to-prod
Copy link
Owner

Description

Use when to call a function based on a condition.

class User
{
    use \Zerotoprod\DataModel\DataModel;
    use \Zerotoprod\DataModelHelper\DataModelHelper;

    #[Describe([
        'cast' => [self::class, 'when'],
        'eval' => '$value >= $context["value_2"]' // The expression to evaluate.
        'true' => [MyAction::class, 'passed'],    // Optional. Invoked when condition is true.
        'false' => [MyAction::class, 'failed'],   // Optional. Invoked when condition is true.
        'required',                               // Throws PropertyRequiredException when value not present.
    ])]
    public string $value;
}

@zero-to-prod zero-to-prod self-assigned this Nov 19, 2024
@zero-to-prod zero-to-prod added the enhancement New feature or request label Nov 19, 2024
@zero-to-prod zero-to-prod merged commit 076e226 into main Nov 19, 2024
3 checks passed
@zero-to-prod zero-to-prod deleted the feat/add-support-for-when-method branch November 19, 2024 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant