Skip to content

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

Closed
wants to merge 24 commits into from

Conversation

javiereguiluz
Copy link
Member

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!

@mickaelandrieu
Copy link
Contributor

👍 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

classees => classes

Copy link
Member Author

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)));
Copy link
Contributor

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()
));

Copy link
Member Author

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.

@javiereguiluz
Copy link
Member Author

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Packagist_

@wouterj
Copy link
Member

wouterj commented Jul 2, 2016

👍

Status: reviewed

* :doc:`/components/validator/index`

* :doc:`/components/validator/introduction`
* :doc:`/components/validator/resources`
Copy link
Member

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

@javiereguiluz
Copy link
Member Author

I've fixed all the reported errors. Thanks for reviewing it!

// ...

class User
{
Copy link
Member

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.

Copy link
Member Author

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::
Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member

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.

@javiereguiluz
Copy link
Member Author

This is finally ready for merging it. Thanks!

@weaverryan
Copy link
Member

Finished at #6798!

@weaverryan weaverryan closed this Jul 31, 2016
weaverryan added a commit that referenced this pull request Aug 1, 2016
…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
@javiereguiluz javiereguiluz deleted the pr/5661 branch May 24, 2018 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants