Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Get started with the Validator docs
  • Loading branch information
wouterj committed Mar 22, 2014
commit 29a4cc25d661904950a70da7086db0fc59de76da
1 change: 1 addition & 0 deletions 1 components/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ The Components
stopwatch
templating/index
translation/index
validator/index
yaml/index

.. include:: /components/map.rst.inc
4 changes: 4 additions & 0 deletions 4 components/map.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@
* :doc:`/components/translation/introduction`
* :doc:`/components/translation/usage`

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

* :doc:`/components/validator/introduction`

* :doc:`/components/yaml/index`

* :doc:`/components/yaml/introduction`
Expand Down
7 changes: 7 additions & 0 deletions 7 components/validator/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Validator
=========

.. toctree::
:maxdepth: 2

introduction
45 changes: 45 additions & 0 deletions 45 components/validator/introduction.rst
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).
Copy link
Contributor

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

Copy link
Member

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)

Copy link
Contributor

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 👶

Copy link
Member Author

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

Copy link
Member

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)


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

Choose a reason for hiding this comment

The 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::
Copy link
Contributor

Choose a reason for hiding this comment

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

string has a specific length

Copy link
Contributor

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

The 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

Copy link
Member Author

Choose a reason for hiding this comment

The 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).

Copy link
Member Author

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

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

let's avoid let's 👶

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 don't think that applies to code blocks, @xabbuh?

Copy link
Member

Choose a reason for hiding this comment

The 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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.