-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Added Validator component documentation #6584
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
Conversation
👍 thank you @javiereguiluz |
The Validator component behavior is based on two concepts: | ||
|
||
* Contraints, which define the rules to be validated; | ||
* Validators, which are the classees that contain the actual validation logic. |
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.
classees => classes
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.
Fixed. Thanks.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
note this call is deprecated since Symfony 2.5
, also we can pass an array of constraints too:
use Symfony\Component\Validator\Validation;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
$validator = Validation::createValidator();
$violations = $validator->validate('Bernhard', array(
new Length(array('min' => 10)),
new NotBlank()
));
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.
Thank you! I've fixed it.
Friendly ping! This PR looks big ... but the docs are new, so there should be no conflicts and the merge should be easy. Thanks! |
.. note:: | ||
|
||
In order to use the annotation loader, you should have installed the | ||
``doctrine/annotations`` and ``doctrine/cache`` packages from _Packagist. |
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.
Packagist_
👍 Status: reviewed |
* :doc:`/components/validator/index` | ||
|
||
* :doc:`/components/validator/introduction` | ||
* :doc:`/components/validator/resources` |
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.
missing the metadata
file here
I've fixed all the reported errors. Thanks for reviewing it! |
// ... | ||
|
||
class User | ||
{ |
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 indentation is broken here.
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.
Fixed.
This ``$validator`` object can validate simple variables such as strings, numbers | ||
and arrays, but it can't validate objects. To do so, use the | ||
:class:`Symfony\\Component\\Validator\\ValidatorBuilder` class to configure the | ||
``Validator`` class:: |
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.
This paragraph looks weird to me. What is the goal behind it and the following code?
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.
I'm not sure, but the paragraph tries to say: "if you want to validate objects, don't use the createValidator()
method. You have to build a validator with the builder class". How would you reword it or improve it?
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 problem I see with this right now is that the code that is shown after the sentence is the same that is already executed in the background when using Validation::createValidator()
. I would then instead just write that you need to configure the validator and link to the resources chapter instead.
This is finally ready for merging it. Thanks! |
Finished at #6798! |
…ereguiluz, weaverryan) This PR was merged into the 2.7 branch. Discussion ---------- Finishing Validator Docs This replaces #6584 - putting it into the new structure. The PR was previously finished, so as long as all the references, etc are in the right place, this should be good to go! Commits ------- dc4d09a fixing reference 53a18d2 fixing bad reference fbe3402 Moving things around for the new structure 49a20e8 Final rewords a65855f Lots of minor fixes 8f4c292 Added a missing trailing comma b38ed60 Fixed RST syntax 0708bca Fixed typos 730781b Updated the code of the example 5909966 Fixed a typo 1e69e63 Finished the first version of the Validator documentation da02759 started to migrate metadata part from book to component docs e30d521 WouterJ comments 07a344c add example on how to use the static method loader 220f194 updated toc tree 2f2023d re added metadata section 21fde5c added custom validation section 5c0082a built the toc tree 6e4aaa3 added new sections 84027d5 added Packagist link 58d0fa5 fixed backslash on namespaces 7007300 @ricardclau review 84f4524 Applied comments by @cordoval c024ef2 Added article about loaders e50e2fa Added small configuration section 4549504 Get started with the Validator docs
This PR finishes the great work made by @wouterj and @mickaelandrieu. I've just added some rewords, simplified some things and removed empty articles. This should be mergeable now. Thanks!