-
Notifications
You must be signed in to change notification settings - Fork 771
Create a "Get started" page #1594
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
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| --- | ||
| weight: -100 | ||
| --- | ||
|
|
||
| # Getting Started | ||
|
|
||
| Welcome to Respect\Validation! | ||
|
|
||
| This guide will help you get up and running with the library quickly. | ||
|
|
||
| ## Installation | ||
|
|
||
| To install Respect\Validation, use [Composer](http://getcomposer.org): | ||
|
|
||
| ```shell | ||
| composer require respect/validation:^3.0 | ||
| ``` | ||
|
|
||
| Ensure you have PHP 8.5 or above installed. | ||
|
alganet marked this conversation as resolved.
|
||
|
|
||
| ## Basic usage | ||
|
|
||
| The `ValidatorBuilder` (aliased as `v` for convenience) provides a fluent interface for building validators and running them. | ||
|
|
||
| ### Validating using exceptions | ||
|
|
||
| The `assert()` method throws an exception when validation fails. Handle these exceptions with `try/catch` for robust error handling: | ||
|
|
||
| ```php | ||
| try { | ||
| v::intType()->assert($input); | ||
| } catch (Throwable $exception) { | ||
| echo 'Validation failed: ' . $exception->getMessage(); | ||
| } | ||
| ``` | ||
|
|
||
| ### Validating without exceptions | ||
|
|
||
| The `validate()` method returns a `ResultQuery` object that allows you to inspect and display validation results: | ||
|
|
||
| ```php | ||
| $result = v::intType()->validate($input); | ||
| if (!$result->isValid()) { | ||
| echo 'Validation failed: ' . $result->getMessage(); | ||
| } | ||
| ``` | ||
|
|
||
| ### Validating using booleans | ||
|
|
||
| Use the `isValid()` method to check if your input meets specific validation criteria: | ||
|
|
||
| ```php | ||
| if (!v::intType()->isValid($input)) { | ||
| echo 'The input you gave me is not an integer'; | ||
| } | ||
| ``` | ||
|
|
||
| ## Key Features | ||
|
|
||
| ### Complex validation | ||
|
|
||
| Combine multiple validators for complex validation rules: | ||
|
|
||
| ```php | ||
| v::numericVal()->positive()->between(1, 255)->assert($input); | ||
| ``` | ||
|
|
||
| ### Custom error messages | ||
|
|
||
| Define your own error messages when validation fails: | ||
|
|
||
| ```php | ||
| v::between(1, 256)->assert($input, '{{subject}} is not what I was expecting'); | ||
| ``` | ||
|
|
||
| ### Custom exceptions | ||
|
|
||
| Throw your own exceptions when the validation fails: | ||
|
|
||
| ```php | ||
| try { | ||
| v::between(1, 256)->assert($input, new DomainException('Not within the expected range')); | ||
| } catch (DomainException $exception) { | ||
| echo 'Custom exception caught: ' . $exception->getMessage(); | ||
| } | ||
| ``` | ||
|
henriquemoody marked this conversation as resolved.
|
||
|
|
||
| ### Reusing validators | ||
|
|
||
| Create validators once and reuse them across multiple inputs: | ||
|
|
||
| ```php | ||
| $validator = v::alnum()->lowercase(); | ||
|
|
||
| $validator->assert('respect'); | ||
| $validator->assert('validation'); | ||
| ``` | ||
|
|
||
| ## Next steps | ||
|
|
||
| - Explore the [Feature Guide](feature-guide.md) for more advanced usage. | ||
| - Check out the [List of Validators by Category](list-of-validators-by-category.md) for a comprehensive list of available validators. | ||
This file was deleted.
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.
Uh oh!
There was an error while loading. Please reload this page.