-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[WIP] Documenting the Validator component #3710
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Validator | ||
========= | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
introduction |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
.. index:: | ||
single: Validator | ||
single: Components; Validator | ||
|
||
The Validator Component | ||
======================= | ||
|
||
The Validator component provides tools to validate values following the | ||
`JSR-303 Bean Validation specification`_. | ||
|
||
Installation | ||
------------ | ||
|
||
You can install the component in 2 different ways: | ||
|
||
* :doc:`Install it via Composer </components/using_components>` (``symfony/validator`` on `Packagist`_); | ||
* Use the official Git repository (https://github.com/symfony/Validator). | ||
|
||
Usage | ||
----- | ||
|
||
The Validator component allows you to use very advanced validation rules, but | ||
it is also really easy to do very minor validation. For instance, if you want | ||
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. really easy to use for simple validation tasks. I believe the usage of "very minor" "very large" or could just be shorted by "minor" or "large". I mean it is a bit redundant. |
||
to validate a string against a specific length, the only code you need is:: | ||
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. string has a specific length 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. string length falls into certain range ... seeing the example |
||
|
||
use Symfony\Component\Validator\Validation; | ||
use Symfony\Component\Validator\Constraints\Length; | ||
|
||
$validator = Validation::createValidator(); | ||
|
||
$violations = $validator->validateValue('Bernhard', new Length(array('min' => 10))); | ||
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. would be good to put an example that fails to show some more detail on the output 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. The string is 8 characters long, while the constraints expects a minimum of 10 character. So it already fails. However, I agree that we should put some "show error" logic in here (I copied this example from the README). 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. actually, it's already in there.... |
||
|
||
if (0 !== count($violations)) { | ||
// there are errors, let's show them | ||
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. let's avoid let's 👶 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. I don't think that applies to code blocks, @xabbuh? 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. I'm used to complain about the first person perspective in code blocks too. But honestly I'm not sure if we ever agreed on that at all. |
||
foreach ($violations as $violation) { | ||
echo $violation->getMessage().'<br>'; | ||
} | ||
} | ||
|
||
Sections | ||
-------- | ||
|
||
* :doc:`/components/validator/configuration` | ||
|
||
.. _`JSR-303 Bean Validation specification`: http://jcp.org/en/jsr/detail?id=303 |
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.
are we doing everywhere the https:// and not the git@github.com? just curious
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.
Using
git@github.com
requires setting up SSH for your account, which does not provide any value when accessing public reposiitories in a read-only way (it used to be reserved to collaborators btw, but I think this has changed)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.
yeah and it is far a better practice to get people into contributing and learning. We shouldn't assume all are read-only people 👶
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.
the component repos are read-only, so it's only for read-only people. And if you want to contribute, you look into the contributing docs and not this docs
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.
And the https url is not a read-only URL either (and anyway, even contributors should not push to the symfony repo directly but to their fork, as everything goes through PRs even for the core team)