This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Form
Fabien Potencier 5314836d3c merged branch Herzult/feature/collection_size_validator (PR #4149)
Commits
-------

3a5e84f [Validator] Add CollectionSize constraint

Discussion
----------

[Validator] Add CollectionSize constraint

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: -
Todo: -

I will also send a PR to the documentation as soon as this one is accepted.

---------------------------------------------------------------------------

by bschussek at 2012-04-29T08:24:28Z

-1

I dislike the rising amount of very specific constraints in the core. Can't we add this to Size?

---------------------------------------------------------------------------

by vicb at 2012-04-29T09:01:39Z

@bschussek #3918 implements what you propose but then the messages are not valid any more:

```php
<?php
    public $minMessage = 'This value should be {{ limit }} or more';
    public $maxMessage = 'This value should be {{ limit }} or less';
    public $invalidMessage = 'This value should be a valid number';
```

I can imagine 2 solutions:

- adding some more message,
- rename the `Size` constraint to `Range` and create a new `Size` constraint for arrays / countables.

What do you think ?

---------------------------------------------------------------------------

by bschussek at 2012-04-29T09:27:53Z

I'd prefer the second solution and merge `Size` with `SizeLength` as well.

---------------------------------------------------------------------------

by vicb at 2012-04-29T09:34:50Z

@bschussek It would make sense. @makasim @Herzult any one of you would like to contribute this (i.e. rename the current Size to Range and create a new Size supporting arrays / countables / strings) ?

---------------------------------------------------------------------------

by Herzult at 2012-04-29T14:31:12Z

Yep, I'm on it.

---------------------------------------------------------------------------

by stof at 2012-04-29T15:22:44Z

@Herzult could you take the other comment into account and merge SizeLength into you Size ?

---------------------------------------------------------------------------

by vicb at 2012-04-29T15:33:05Z

The guessers should also be modified (it might also affect the ODM which is in an other repo, if so it would be good to sync the changes).

---------------------------------------------------------------------------

by Herzult at 2012-04-29T16:38:19Z

@stof the problem merging SizeLength into Size is that they don't have the same required options & messages.

---------------------------------------------------------------------------

by Herzult at 2012-04-29T16:47:40Z

And what about renaming Range to Interval and SizeLength to IntervalLength?

---------------------------------------------------------------------------

by stof at 2012-04-29T16:54:38Z

Well, SizeLength is about matching the length of a string currently. Nothing related to intervals

---------------------------------------------------------------------------

by Herzult at 2012-04-29T17:29:40Z

Here are the current names:

 * **Size** for collection (countable) size
 * **Range** for numbers
 * **SizeLength** for strings

Merging **SizeLength** into **Size** is maybe not appropriate because collections and strings are different things. It'll be hard to find messages that fit both collections and strings. Maybe we had better to find a better name for both. What do you think?

About the ValidatorTypeGuesser, I'll update it as soon as we know ow to name the constraints.

---------------------------------------------------------------------------

by vicb at 2012-04-29T17:43:01Z

Size is a good name for both strings and "collections", could we have two sets of strings and select according to the type ?

---------------------------------------------------------------------------

by Herzult at 2012-04-29T22:39:55Z

I tried to merge them together, what do you think?

---------------------------------------------------------------------------

by vicb at 2012-04-30T06:52:37Z

I think your changes are great, may be @bschussek has more feedback. The ValidatorTypeGuesser and the translation are yet to be updated.

---------------------------------------------------------------------------

by hhamon at 2012-05-01T12:32:28Z

Am I missing something or `SizeLength` for strings is a duplicate for `MinLength` and `MaxLength` constraints?

---------------------------------------------------------------------------

by Herzult at 2012-05-02T13:29:36Z

Yep, that's true. But the only link between this PR and the SizeLength constraint is that I merged it to the one I introduced.

---------------------------------------------------------------------------

by Herzult at 2012-05-07T07:48:01Z

@bschussek what do you think?

---------------------------------------------------------------------------

by vicb at 2012-05-10T19:51:26Z

@Herzult this PR looks good to me, could you update the changelog and update guides, try to factorize the code and squash the commits ? Thanks.

---------------------------------------------------------------------------

by travisbot at 2012-05-11T15:42:35Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1306112) (merged 8d8e6443 into 4ac3bddb).

---------------------------------------------------------------------------

by vicb at 2012-05-11T21:42:21Z

* could #4259 be helpful ?
* please squash the commits.
* please create a PR / issue on [symfony-docs](https://github.com/symfony/symfony-docs)

thanks for the updates.

---------------------------------------------------------------------------

by travisbot at 2012-05-13T18:38:18Z

This pull request [fails](http://travis-ci.org/symfony/symfony/builds/1321123) (merged eeda9044 into 4ac3bddb).

---------------------------------------------------------------------------

by travisbot at 2012-05-13T18:45:12Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1321146) (merged 491ca19a into 8b54eb56).

---------------------------------------------------------------------------

by travisbot at 2012-05-14T11:29:39Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1326110) (merged 44865024 into 8b54eb56).

---------------------------------------------------------------------------

by vicb at 2012-05-14T11:49:37Z

@Herzult what about plural translations ?

---------------------------------------------------------------------------

by travisbot at 2012-05-14T16:52:37Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1328677) (merged 93480f95 into 46ffbd52).

---------------------------------------------------------------------------

by travisbot at 2012-05-14T17:03:13Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1328705) (merged 326c3b81 into 46ffbd52).

---------------------------------------------------------------------------

by vicb at 2012-05-14T20:19:18Z

thanks for the updates, this PR looks fine to me. @bschussek ?

---------------------------------------------------------------------------

by vicb at 2012-05-16T06:45:51Z

@Herzult can you squash your commits ?

---------------------------------------------------------------------------

by travisbot at 2012-05-16T11:20:44Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1344811) (merged 3a5e84f4 into 58b6ef23).
2012-05-16 14:22:22 +02:00
..
Event fixed CS 2011-06-08 12:16:48 +02:00
Exception [Form] Moved Options classes to new OptionsParser component 2012-05-14 19:35:07 +02:00
Extension merged branch Herzult/feature/collection_size_validator (PR #4149) 2012-05-16 14:22:22 +02:00
Guess fixed phpdoc @param alignment 2012-05-15 22:19:31 +02:00
Resources/config [Form] Deprecated FormValidatorInterface and moved implementations to event listeners 2012-04-13 16:42:01 +02:00
Tests merged branch bschussek/options (PR #3968) 2012-05-15 10:14:33 +02:00
Util fixed phpdoc @param alignment 2012-05-15 22:19:31 +02:00
.gitignore [Components] Tests/Autoloading fixes 2012-05-01 17:51:41 +02:00
AbstractExtension.php Remove useless code 2011-07-04 14:08:20 +02:00
AbstractType.php fixed phpdoc @param alignment 2012-05-15 22:19:31 +02:00
AbstractTypeExtension.php fixed phpdoc @param alignment 2012-05-15 22:19:31 +02:00
CallbackTransformer.php fixed phpdoc @param alignment 2012-05-15 22:19:31 +02:00
CallbackValidator.php [Form] Deprecated FormValidatorInterface and moved implementations to event listeners 2012-04-13 16:42:01 +02:00
CHANGELOG.md fixed CS 2012-05-01 15:23:48 +02:00
composer.json [OptionsParser] Renamed OptionsParser to OptionsResolver 2012-05-14 19:35:07 +02:00
DataMapperInterface.php fixed CS 2011-06-08 12:16:48 +02:00
DataTransformerInterface.php fixed phpdoc @param alignment 2012-05-15 22:19:31 +02:00
Form.php fixed phpdoc @param alignment 2012-05-15 22:19:31 +02:00
FormBuilder.php fixed phpdoc @param alignment 2012-05-15 22:19:31 +02:00
FormError.php fixed phpdoc @param alignment 2012-05-15 22:19:31 +02:00
FormEvents.php [Form] Deprecated FormValidatorInterface and moved implementations to event listeners 2012-04-13 16:42:01 +02:00
FormExtensionInterface.php [Form] phpDoc 2011-05-13 11:00:04 +02:00
FormFactory.php fixed phpdoc @param alignment 2012-05-15 22:19:31 +02:00
FormFactoryInterface.php fixed phpdoc @param alignment 2012-05-15 22:19:31 +02:00
FormInterface.php fixed phpdoc @param alignment 2012-05-15 22:19:31 +02:00
FormTypeExtensionInterface.php fixed phpdoc @param alignment 2012-05-15 22:19:31 +02:00
FormTypeGuesserChain.php fixed phpdoc @param alignment 2012-05-15 22:19:31 +02:00
FormTypeGuesserInterface.php fixed phpdoc @param alignment 2012-05-15 22:19:31 +02:00
FormTypeInterface.php fixed phpdoc @param alignment 2012-05-15 22:19:31 +02:00
FormValidatorInterface.php [Form] Deprecated FormValidatorInterface and moved implementations to event listeners 2012-04-13 16:42:01 +02:00
FormView.php fixed phpdoc @param alignment 2012-05-15 22:19:31 +02:00
LICENSE Updated LICENSE files copyright 2012-02-22 10:10:37 +01:00
phpunit.xml.dist [Components] Tests/Autoloading fixes 2012-05-01 17:51:41 +02:00
README.md [Components] Tests/Autoloading fixes 2012-05-01 17:51:41 +02:00
ReversedTransformer.php [Form] Fix the ReversedTransform class 2011-05-10 20:25:22 +02:00

Form Component

Form provides tools for defining forms, rendering and binding request data to related models. Furthermore it provides integration with the Validation component.

Resources

Silex integration:

https://github.com/fabpot/Silex/blob/master/src/Silex/Provider/FormServiceProvider.php

Documentation:

http://symfony.com/doc/2.0/book/forms.html

Resources

You can run the unit tests with the following command:

phpunit

If you also want to run the unit tests that depend on other Symfony Components, install dev dependencies before running PHPUnit:

php composer.phar install --dev