Skip to content

[Constraints] Added missing formats #2214

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 2 commits into from
Feb 14, 2013
Merged
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
1 change: 1 addition & 0 deletions reference/constraints/File.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ below a certain file size and a valid PDF, add the following:
// src/Acme/BlogBundle/Entity/Author.php
namespace Acme\BlogBundle\Entity;

// ...
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints\File;

Expand Down
31 changes: 31 additions & 0 deletions reference/constraints/Min.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,37 @@ the following:
protected $age;
}

.. code-block:: xml

<!-- src/Acme/EventBundle/Resources/config/validation.yml -->
<class name="Acme\EventBundle\Entity\Participant">
<property name="age">
<constraint name="Min">
<option name="limit">18</option>
<option name="message">You must be 18 or older to enter</option>
Copy link
Contributor

Choose a reason for hiding this comment

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

A . at the end should be added to be compliant with most of the constraint entries, shouldn't it?

I know it is really minor but for unification's sake

Copy link
Member Author

Choose a reason for hiding this comment

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

@ricarclau, although this is minor it is one of the most important things in the documentation. Consistency is the easiest thing for beginners in tutorials. If they see other things on every page, they will get confused. My target for this documentation is to have a documentation that looks like it is made by one man, but has a big community behind it.

Did you fixed the other sentences in this document?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not for this document as it would conflict your changes. I guess best option is that you add . in all parts of constraints/Min and I'll check the rest of constraints.

Copy link
Member Author

Choose a reason for hiding this comment

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

@ricardclau, I have added the interpunction.

</constraint>
</property>
</class>

.. code-block:: php

// src/Acme/EventBundle/Entity/Participant.php
namespace Acme\EventBundle\Entity\Participant;

use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints as Assert;

class Participant
{
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('age', new Assert\Min(array(
'limit' => '18',
'message' => 'You must be 18 or older to enter',
));
}
}

Options
-------

Expand Down
20 changes: 20 additions & 0 deletions reference/constraints/Regex.rst
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,26 @@ message:
</property>
</class>

.. code-block:: php

// src/Acme/BlogBundle/Entity/Author.php
namespace Acme\BlogBundle\Entity;

use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints as Assert;

class Author
{
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('firstName', new Assert\Regex(array(
'pattern' => '/\d/',
'match' => false,
'message' => 'Your name cannot contain a number',
)));
}
}

Options
-------

Expand Down