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 runInline method #64

Merged
merged 5 commits into from
Apr 26, 2024
Merged

Add runInline method #64

merged 5 commits into from
Apr 26, 2024

Conversation

ash-jc-allen
Copy link
Owner

There may be times when you want to run the validator with inline rules instead of using the rules defined in your config validation files. This can be useful if you want to run a one-off validation check, or validate the config values inside a package you maintain.

To do this, you can use the runInline method like so:

use AshAllenDesign\ConfigValidator\Services\ConfigValidator;
use AshAllenDesign\ConfigValidator\Services\Rule;

$configValidator = new ConfigValidator();

$configValidator->runInline([
    'app' => [
        Rule::make('env')->rules(['in:local,production']),
        Rule::make('debug')->rules(['boolean']),
    ],
    'mail' => [
        Rule::make('driver')->rules(['in:smtp,sendmail,mailgun,ses,postmark,log,array']),
    ],
]);

In the example above, we're running the validator with inline rules for the app and mail config files. The rules are the same as the ones we would define in the config validation files.

The behaviour of the runInline method is the same as the run method. It will throw an exception if the validation fails, or return a boolean value if the throwExceptionOnFailure method has been set to false.

@ash-jc-allen ash-jc-allen merged commit 11b2646 into master Apr 26, 2024
26 checks passed
@ash-jc-allen ash-jc-allen deleted the feature/run-inline branch April 26, 2024 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants