Commit Graph

2187 Commits

Author SHA1 Message Date
Sebastian Hörl
815c769292 [Validator] Renamed getValidationGroups to getGroupSequence 2012-02-02 20:27:50 +01:00
Sebastian Hörl
d84a2e4bdf [Validator] Updated test expectations 2012-02-02 20:27:50 +01:00
Sebastian Hörl
9f2310b2f8 [Validator] Fixed typos, renamed hasGroupSequenceProvider 2012-02-02 20:27:50 +01:00
Sebastian Hörl
e0d28284fc [Validator] GroupSequenceProvider tests improved, configuration changed 2012-02-02 20:27:50 +01:00
Sebastian Hörl
c3b04a3336 [Validator] Changed GroupSequenceProvider implementation 2012-02-02 20:27:50 +01:00
Sebastian Hörl
6c4455fef7 [Validator] Added GroupSequenceProvider 2012-02-02 20:27:49 +01:00
Christophe Coevoet
045f936038 Changed the testcase to expect the unescaping only after the resolution
String values are not unescaped either in resolveValue() because it can
be called several times for the same parameter.
2012-02-02 18:34:05 +01:00
lsmith77
a1b6d4c46b Added a failing testcase for escaped % in array parameters 2012-02-02 18:33:55 +01:00
Fabien Potencier
2cd246786d merged branch bschussek/issue3239 (PR #3256)
Commits
-------

8714d79 [Form] Simplified code in MergeCollectionListener
8ab982a [Form] Fixed: Custom add and remove method are not invoked if disallowed
02f61ad [Form] Renamed choice and collection options "adder_prefix" and "remover_prefix" to "add_method" and "remove_method" and allowed to specify full method names
b393774 [Form] Used direct method access in MergeCollectionListener instead of Reflection to avoid problems when using class hierarchies
d208f4e [Form] Made it possible to use models with only either addXxx() or removeXxx()

Discussion
----------

[Form] Fixed edge cases in MergeCollectionListener

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

![Travis Build Status](https://secure.travis-ci.org/bschussek/symfony.png?branch=issue3239)

Fixes an issue mentioned in the comments of #3239

see https://github.com/symfony/symfony/pull/3239#issuecomment-3776312

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

by bschussek at 2012-02-02T12:12:17Z

Wait a minute before merging this.

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

by bschussek at 2012-02-02T13:01:55Z

@fabpot Ready to merge
2012-02-02 17:28:40 +01:00
Bernhard Schussek
bd461e295d [Form] Forms now don't create empty objects anymore if they are completely empty and not required. The empty data for these forms is null. 2012-02-02 14:40:19 +01:00
Bernhard Schussek
8ab982afc8 [Form] Fixed: Custom add and remove method are not invoked if disallowed 2012-02-02 13:53:44 +01:00
Bernhard Schussek
02f61adcc5 [Form] Renamed choice and collection options "adder_prefix" and "remover_prefix" to "add_method" and "remove_method" and allowed to specify full method names 2012-02-02 13:44:48 +01:00
Bernhard Schussek
d208f4e0de [Form] Made it possible to use models with only either addXxx() or removeXxx() 2012-02-02 12:53:46 +01:00
Fabien Potencier
0914a38e74 merged branch bschussek/issue3161 (PR #3253)
Commits
-------

9a4e22e [Form] Disallowed infinity in NumberToLocalizedStringTransformer

Discussion
----------

[Form] Disallowed infinity in NumberToLocalizedStringTransformer

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

![Travis Build Status](https://secure.travis-ci.org/bschussek/symfony.png?branch=issue3161)
2012-02-02 12:27:10 +01:00
Bernhard Schussek
9a4e22efe7 [Form] Disallowed infinity in NumberToLocalizedStringTransformer 2012-02-02 12:15:50 +01:00
Dariusz Górecki
d02f17268e Code readability fixes, removed unneeded typecasts and checks
Bug fix: no
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: -
Todo: -
2012-02-02 11:43:31 +01:00
Fabien Potencier
baa63b8077 merged branch bschussek/issue1540 (PR #3239)
Commits
-------

9b0245b [Form] Made prefix of adder and remover method configurable. Adders and removers are not called if "by_reference" is disabled.
49d1464 [Form] Implemented MergeCollectionListener which calls addXxx() and removeXxx() in your model if found
7837f50 [Form] Added FormUtil::singularify()

Discussion
----------

[Form] Forms now call addXxx() and removeXxx() in your model

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: #1540
Todo: adapt documentation

![Travis Build Status](https://secure.travis-ci.org/bschussek/symfony.png?branch=issue1540)

Adds functionality for calling `addXxx` and `removeXxx` method in your model. All types returning a collection of values are affected: "collection", "choice" (with multiple selection) and "entity" (with multiple selection).

Example:

    class Article
    {
        public function addTag($tag) { ... }
        public function removeTag($tag) { ... }
        public function getTags($tag) { ... }
    }

And the controller:

    $form = $this->createFormBuilder($article)
        ->add('tags')
        ->getForm();

Upon modifying the form, addTag() and removeTag() are now called appropiately.

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

by stof at 2012-02-01T18:23:49Z

Really great

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

by vicb at 2012-02-01T18:24:04Z

Great !!

Two suggestions:

* make "add" and "remove" configurable,
* introduce a base class for the remove listeners with (final?) `::getSubscribedEvents()` and `::getEventPriorities()`

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

by haswalt at 2012-02-01T18:57:46Z

+1 this

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

by daFish at 2012-02-01T19:54:46Z

+1

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

by michelsalib at 2012-02-01T20:55:37Z

Can wait to have it!
It will save lots of time trying to solve WTF effects and making workarounds.

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

by bschussek at 2012-02-02T09:37:12Z

@vicb: Your first point is done. The second, I don't understand.

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

by stof at 2012-02-02T09:40:50Z

@bschussek your branch conflicts with master according to github

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

by vicb at 2012-02-02T09:52:40Z

@bschussek my point is that I can stand hard-coded priorities which are error prone. A better solution might be to introduce constants (in `FormEvents` / `FormEventPriorities` ?) with meaningful names.

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

by bschussek at 2012-02-02T10:21:52Z

@stof Rebased

@vicb I know, but who is responsible for managing priorities? There is no central entitty that can do this. (btw this is a general problem of the priority system of the EventDispatcher)

@fabpot Ready to merge.

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

by vicb at 2012-02-02T10:23:28Z

@bschussek doesn't each form has is own dispatcher so there is no need for a global registry here, something local to the form could be good enough.
2012-02-02 11:25:38 +01:00
Fabien Potencier
3c8d300125 fixed CS 2012-02-02 11:21:34 +01:00
Bernhard Schussek
9b0245b57b [Form] Made prefix of adder and remover method configurable. Adders and removers are not called if "by_reference" is disabled. 2012-02-02 11:16:57 +01:00
Bernhard Schussek
49d1464b43 [Form] Implemented MergeCollectionListener which calls addXxx() and removeXxx() in your model if found
The listener is used by the Collection type as well as the Choice and Entity type (with multiple
selection). The effect is that you can have for example this model:

    class Article
    {
        public function addTag($tag) { ... }
        public function removeTag($tag) { ... }
        public function getTags($tag) { ... }
    }

You can create a form for the article with a field "tags" of either type "collection" or "choice"
(or "entity"). The field will correctly use the three methods of the model for displaying and
editing tags.
2012-02-02 11:16:21 +01:00
Bernhard Schussek
7837f50c73 [Form] Added FormUtil::singularify() 2012-02-02 11:15:49 +01:00
Fabien Potencier
8245bf13d5 merged branch bschussek/issue2615 (PR #3228)
Commits
-------

2e4ebe4 [Validator] Renamed methods addViolationAtRelativePath() and getAbsolutePropertyPath() in ExecutionContext
9153f0e [Validator] Deprecated ConstraintValidator methods setMessage(), getMessageTemplate() and getMessageParameters()
0417282 [Validator] Fixed typos
a30a679 [Validator] Made ExecutionContext immutable and introduced new class GlobalExecutionContext
fe85bbd [Validator] Simplified ExecutionContext::addViolation(), added ExecutionContext::addViolationAt()
f77fd41 [Form] Fixed typos
1fc615c Fixed string access by curly brace to bracket
a103c28 [Validator] The Collection constraint adds "missing" and "extra" errors to the individual fields now
f904a9e [Validator] Fixed: GraphWalker does not add constraint violation if error message is empty
1dd302c [Validator] Fixed ConstraintViolationList::__toString() to not include dots in the output if the root is empty
1678a3d [Validator] Fixed: Validator::validateValue() propagates empty validation root instead of the provided value

Discussion
----------

[Validator] Improved "missing" and "extra" errors of Collection constraint

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

![Travis Build Status](https://secure.travis-ci.org/bschussek/symfony.png?branch=issue2615)

Instead of a single violation

    Array:
        The fields "foo", "bar" are missing

various violations are now generated.

    Array[foo]:
        This field is missing
    Array[bar]:
        This field is missing

Apart from that, the PR contains various minor fixes to the Validator.

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

by bschussek at 2012-02-02T09:14:52Z

@fabpot Ready for merge.
2012-02-02 10:16:32 +01:00
Fabien Potencier
569b6dbd13 merged branch hason/formbuilder (PR #3249)
Commits
-------

7cecb4e [Form] added support for parent of FormBuilder

Discussion
----------

[Form] added support for parent of FormBuilder

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

In some cases of building forms, it is good to know the attributes of the parent builder. In my case I want to automaticaly add the subscriber to the fields, whose parent builder has a concrete attribute.

Replace #2882
2012-02-02 10:13:41 +01:00
Bernhard Schussek
2e4ebe444f [Validator] Renamed methods addViolationAtRelativePath() and getAbsolutePropertyPath() in ExecutionContext 2012-02-02 10:13:41 +01:00
Martin Hasoň
7cecb4e71e [Form] added support for parent of FormBuilder 2012-02-02 10:09:50 +01:00
Fabien Potencier
0f86c4585d merged branch havvg/acl-unset-parent-master (PR #3222)
Commits
-------

6a02237 add note on BC BREAK of MutableAclInterface
dbd3a1b allow unsetting parentAcl on MutableAclInterface

Discussion
----------

[Security] allow unsetting the parent ACL

Bug fix: yes
Feature addition: no
Backwards compatibility break: yes
Symfony2 tests pass: yes

The #3151 rebased onto master.
Sorry for the delay, was on vacations.

```plain
 symfony2 git:acl-unset-parent ✔  phpunit tests/Symfony/Tests/Component/Security         ~/Web Development/symfony2
PHPUnit 3.6.4 by Sebastian Bergmann.

Configuration read from /Users/havvg/Web Development/symfony2/phpunit.xml

...............................................................  63 / 428 ( 14%)
............................................................... 126 / 428 ( 29%)
............................................................... 189 / 428 ( 44%)
............................................................... 252 / 428 ( 58%)
............................................................... 315 / 428 ( 73%)
............................................................... 378 / 428 ( 88%)
.................................................

Time: 15 seconds, Memory: 49.00Mb

OK (427 tests, 1180 assertions)
```
2012-02-02 10:09:03 +01:00
Fabien Potencier
e71d1579d1 merged branch helmer/readonly (PR #3193)
Commits
-------

de253dd [Form] read_only and disabled attributes

Discussion
----------

[Form] read_only and disabled attributes (closes #1974)

1. Removed ``readOnly`` property from ``Form``, as it is no longer required
2. Introduced ``disabled`` property to ``Form``, behaves exactly like ``readOnly`` used to
3. Added ``disabled`` property to fields, defaults to ``false``, renders as ``disabled="disabled"``
4. A field with positive ``read_only`` property now renders as ``readonly="readonly"``

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

by helmer at 2012-01-26T17:46:17Z

I changed ``Form`` and ``FormBuilder`` property ``readOnly`` to ``disabled``. On second thought, this is perhaps not such good change - while readOnly somewhat implied the use-case, disabled no longer does.

Perhaps something else, like ``bindable`` (as not to confuse with read_only attribute of Fields)?

@bschussek, others, any thoughts?

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

by bschussek at 2012-01-31T06:53:59Z

Please prefix commits with the affected component, if applicable.

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

by helmer at 2012-01-31T08:41:03Z

@bschussek Prefixed. Please also see see to [this question](https://github.com/symfony/symfony/pull/3193#issuecomment-3673074)
2012-02-02 10:03:00 +01:00
Fabien Potencier
9fa3201c11 removed unneeded code 2012-02-02 10:00:42 +01:00
Sebastian Bergmann
253a8ff016 [DependencyInjection] split a test 2012-02-02 09:51:16 +01:00
Fabien Potencier
1c3e6c2cb2 merged branch sellingsource/EXPOSE_FORM_VALIDATORS (PR #2983)
Commits
-------

601d462 [Form] Added getValidators() to Form class

Discussion
----------

[Form] Added getValidators() to Form class

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes

I am working implementing client side validation in a bundle that adds validation rules via a form builder. I am currently unable to pull the validators from the Form class which is making the implementation incredibly difficult.

I noticed that the transformers are currently exposed and based on some feedback I got on IRC I am guessing these weren't exposed simply because no one needed them at the time.

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

by mlively at 2011-12-28T20:54:41Z

Side note: It would be incredibly helpful to have this in the current branch of symfony. I implemented it on master because it is a new feature, but I would be more than happy to patch it into 2.0 if you would like.

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

by canni at 2012-01-11T10:15:46Z

👍

As this is new feature it cannot fit into 2.0 series, but 2.1 is just few clicks ahead, maybe this feature will  fit into  ;)

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

by bschussek at 2012-01-31T08:23:05Z

ping @fabpot
👍

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

by stof at 2012-01-31T08:51:26Z

@mlively could you rebase your branch ? it conflicts with the current master

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

by mlively at 2012-01-31T21:38:39Z

Yes, I can do that might be later today.
2012-02-02 09:36:07 +01:00
Eric Clemmons
c373d5b656 Added RouteCollectionTest#testAddCollectionOverridesDefaultsAndRequirements 2012-02-01 21:10:50 -08:00
Bart van den Burg
b228942ac8 fix for entity choice list when ->loaded is false and the class name is an entity shorthand name
and updated tests to work with refactored choicelist
2012-02-01 19:13:06 +01:00
Bernhard Schussek
9153f0e569 [Validator] Deprecated ConstraintValidator methods setMessage(), getMessageTemplate() and getMessageParameters()
Had to refactor the validation tests at the same time and fixed various small bugs while doing so.
2012-02-01 14:03:13 +01:00
Bernhard Schussek
0417282740 [Validator] Fixed typos 2012-02-01 09:21:22 +01:00
Bernhard Schussek
a30a679135 [Validator] Made ExecutionContext immutable and introduced new class GlobalExecutionContext
A new ExecutionContext is now created everytime that GraphWalker::walkConstraint() is
launched. Because of this, a validator B launched from within a validator A can't break
A anymore by changing the context.

Because we have a new ExecutionContext for every constraint validation, there is no point
in modifying its state anymore. Because of this it is now immutable.
2012-01-31 21:35:48 +01:00
Bernhard Schussek
fe85bbdb06 [Validator] Simplified ExecutionContext::addViolation(), added ExecutionContext::addViolationAt() 2012-01-31 18:42:14 +01:00
Fabien Potencier
4682b096f6 merged branch bschussek/issue3156 (PR #3218)
Commits
-------

57cc531 [Form] Improved PHPDocs of choice lists
9e7e2af [Form] Fixed PHPDoc: Used {@inheritdoc} where applicable
2c530cc Fixed typos in UPGRADE file
7899bea Added examples to UPGRADE
d346ae6 Improved choice list sections of UPGRADE and CHANGELOG
a676598 [Form] Added class LazyChoiceList

Discussion
----------

[Form] Added LazyChoiceList

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

![Travis Build Status](https://secure.travis-ci.org/bschussek/symfony.png?branch=issue3156)

Adds a ChoiceList implementation that satisfies people who formerly extended ArrayChoiceList and loaded choices lazily in its `load` method.

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

by craue at 2012-01-30T12:56:49Z

👍

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

by craue at 2012-01-30T14:55:38Z

Not sure if it's a bug in this PR or in #3156, but the labels get replaced by their keys:

```php
<?php

use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList;
use Symfony\Component\Form\Extension\Core\ChoiceList\LazyChoiceList;
use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList;

class MyChoiceList extends LazyChoiceList {
	protected function loadChoiceList() {
		$choices = array(
			'bla' => 'blaaaaaahhhh',
		);
		return new SimpleChoiceList($choices, array(), ChoiceList::COPY_CHOICE, ChoiceList::COPY_CHOICE);
	}

	public function getChoices() {
		$choices = parent::getChoices();

		// $choices is array('bla' => 'bla')

		return $choices;
	}
}
```

If it's not this PR, I can of course open a new ticket for that. But I'm only working with `LazyChoiceList`s.

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

by stof at 2012-01-30T16:07:41Z

@craue the ``SimpleChoiceList`` is an implementation using the same string as label and value. If you need different ones, you need to use the ``ChoiceList`` implementation.

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

by craue at 2012-01-30T16:22:06Z

@stof: That would make `SimpleChoiceList` useless for almost any case. Are you sure?

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

by craue at 2012-01-30T16:33:31Z

The bug even occurs when using

```
return new ChoiceList(array_keys($choices), array_values($choices), array(), ChoiceList::COPY_CHOICE, ChoiceList::COPY_CHOICE);
```

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

by stof at 2012-01-30T16:40:19Z

well, the SimpleChoiceList is for simple cases (thus its naming) where you want the same for the label and the values. And if you look at the class, you will see it extends the ChoiceList implementation which is the generic one.

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

by craue at 2012-01-30T16:53:36Z

For me, "simple" would mean that it just takes the array given, using keys as indices and values as labels. No fancy stuff messing around with anything. :D But, is there anything wrong in this code or in mine? @bschussek: Please enlighten me.

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

by bschussek at 2012-01-30T17:16:58Z

You are both wrong :) `getChoices` does not return the choices with their associated labels anymore. What you get now are the choice indices as array keys and the choice values as array values. How both are determined depends on the index and value generation strategy, which, in your case, are both COPY_CHOICE.

The difference between simple and complex choice lists is, that simple choice lists can only contain scalar values as choices, while other choice lists (such as ObjectChoiceList, EntityChoiceList) may contain objects as choices.

Choice labels are now stored in ChoiceView objects, which are returned by the various `get*Views` methods.

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

by craue at 2012-01-30T18:07:43Z

It's pretty annoying having provided an array with keys and values when initializing the `ChoiceList` but being unable to retrieve it again. Guess I just over-used or even abused those choice lists as kind of (not only form related) lookup tables.

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

by bschussek at 2012-01-30T19:27:21Z

@craue: What's your use case?

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

by craue at 2012-01-30T20:10:16Z

I just used choice lists extensively, even for not directly form-related stuff. In one case, I'm using two of them (which are also used individually) to build up a third one. That went well using the old `ArrayChoiceList`s and their `getChoices` method. Just thinking about creating another set of model classes which just contain my lists. So for only one select field in a form it'll take three classes then: (A) a list, (B) a choice list based on A, (C) a choice form type based on B. Oh well ... :D

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

by craue at 2012-01-30T21:31:32Z

Anyway, this PR for `LazyChoiceList` is great, so please merge it. ;)

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

by craue at 2012-01-31T14:00:46Z

@bschussek: Is it ready to be merged?

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

by bschussek at 2012-01-31T16:59:17Z

Yes
2012-01-31 18:09:24 +01:00
Helmer Aaviksoo
de253dd3dd [Form] read_only and disabled attributes 2012-01-31 11:51:22 +02:00
Victor Berchet
eb540bef29 [Profiler] Allow profiling the terminate event 2012-01-31 08:40:49 +01:00
Bernhard Schussek
a103c28b08 [Validator] The Collection constraint adds "missing" and "extra" errors to the individual fields now 2012-01-30 20:57:20 +01:00
Bernhard Schussek
f904a9ed53 [Validator] Fixed: GraphWalker does not add constraint violation if error message is empty 2012-01-30 20:56:10 +01:00
Bernhard Schussek
1678a3dbdf [Validator] Fixed: Validator::validateValue() propagates empty validation root instead of the provided value 2012-01-30 18:43:47 +01:00
Toni Uebernickel
dbd3a1bcc0 allow unsetting parentAcl on MutableAclInterface 2012-01-30 14:16:44 +01:00
Bernhard Schussek
5aa5987aa4 [Form] Fixed: form children are always validated in group "Default" 2012-01-30 13:42:13 +01:00
Bernhard Schussek
a676598d74 [Form] Added class LazyChoiceList 2012-01-30 10:56:58 +01:00
Fabien Potencier
916597eb29 fixed CS, phpdoc, removed unused use statements 2012-01-28 18:02:36 +01:00
Fabien Potencier
5e0823c99c merged branch bschussek/issue1919 (PR #3156)
Commits
-------

8dc78bd [Form] Fixed YODA issues
600cec7 [Form] Added missing entries to CHANGELOG and UPGRADE
b154f7c [Form] Fixed docblock and unneeded use statement
399af27 [Form] Implemented checks to assert that values and indices generated in choice lists match their requirements
5f6f75c [Form] Fixed outstanding issues mentioned in the PR
7c70976 [Form] Fixed text in UPGRADE file
c26b47a [Form] Made query parameter name generated by ORMQueryBuilderLoader unique
18f92cd [Form] Fixed double choice fixing
f533ef0 [Form] Added ChoiceView class for passing choice-related data to the view
d72900e [Form] Incorporated changes suggested in PR comments
28d2f6d Removed duplicated lines from UPGRADE file
e1fc5a5 [Form] Restricted form names to specific characters to (1) fix generation of HTML IDs and to (2) avoid problems with property paths.
87b16e7 [Form] Greatly improved ChoiceListInterface and all of its implementations

Discussion
----------

[Form] Improved ChoiceList implementation and made form naming more restrictive

Bug fix: yes
Feature addition: yes
Backwards compatibility break: **yes**
Symfony2 tests pass: yes
Fixes the following tickets: #2869, #3021, #1919, #3153
Todo: adapt documentation

![Travis Build Status](https://secure.travis-ci.org/bschussek/symfony.png?branch=issue1919)

The changes in this PR are primarily motivated by the fact that invalid form/field names lead to various problems.

1. When a name contains any characters that are not permitted in HTML "id" attributes, these are invalid
2. When a name contains periods ("."), form validation is broken, because they confuse the property path resolution
3. Since choices in expanded choice fields are directly translated to field names, choices applying to either 1. or 2. lead to problems. But choices should be unrestricted.
4. Unless a choice field is not expanded and does not allow multiple selection, it is not possible to use empty strings as choices, which might be desirable in some occasions.

The solution to these problems is to

* Restrict form names to disallow unpermitted characters (solves 1. and 2.)
* Generate integer indices to be stored in the HTML "id" and "name" attributes and map them to the choices (solves 3.). Can be reverted to the old behaviour by setting the option "index_generation" to ChoiceList::COPY_CHOICE
* Generate integer values to be stored in the HTML "value" attribute and map them to the choices (solves 4.). Can be reverted to the old behaviour by setting the option "value_generation" to ChoiceList::COPY_CHOICE

Apart from these fixes, it is now possible to write more flexible choice lists. One of these is `ObjectChoiceList`, which allows to use objects as choices and is bundled in the core. `EntityChoiceList` has been made an extension of this class.

    $form = $this->createFormBuilder()
        ->add('object', 'choice', array(
            'choice_list' => new ObjectChoiceList(
                array($obj1, $obj2, $obj3, $obj4),
                // property path determining the choice label (optional)
                'name',
                // preferred choices (optional)
                array($obj2, $obj3),
                // property path for object grouping (optional)
                'category',
                // property path for value generation (optional)
                'id',
                // property path for index generation (optional)
                'id'
            )
        ))
        ->getForm()
    ;

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

by kriswallsmith at 2012-01-19T18:09:09Z

Rather than passing `choices` and a `choice_labels` arrays to the view would it make sense to introduce a `ChoiceView` class and pass one array of objects?

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

by stof at 2012-01-22T15:32:36Z

@bschussek can you update your PR according to the feedback (and rebase it as it conflicts according to github) ?

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

by bschussek at 2012-01-24T00:15:42Z

@kriswallsmith fixed

Fixed all outstanding issues. Would be glad if someone could review again, otherwise this PR is ready to merge.

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

by fabpot at 2012-01-25T15:17:59Z

Is it ready to be merged?

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

by Tobion at 2012-01-25T15:35:50Z

Yes I think so. He said it's ready to be merged when reviewed.

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

by bschussek at 2012-01-26T02:30:36Z

Yes.

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

by bschussek at 2012-01-28T12:39:00Z

Fixed outstanding issues. Ready for merge.
2012-01-28 15:19:10 +01:00
Fabien Potencier
a72bf897d3 merged branch vicb/profiler (PR #3190)
Commits
-------

b879397 [Profiler] Optimize time panel IS
d4300b9 [WebProfilerBundle] Tweak the time view
416a2a4 [Stopwatch] Fix some logic
8c3505e [Profiler] Tweak PHPDoc
3bcd154 [HttpKernel] Tweak the Profile class - DRY

Discussion
----------

[Profiler] Stopwatch related tweaks

* Some fixes in the stopwatch logic,
* Some JS fixes,
* Make use of modern JS.
2012-01-28 15:16:32 +01:00
Bernhard Schussek
0533c1b40f [Form] Fixed: IntegerToLocalizedStringTransformer does not accept "NaN" as valid number anymore 2012-01-28 14:21:37 +01:00
Bernhard Schussek
8c63d6d1e5 [Form] Fixed: NumberToLocalizedStringTransformer does not accept "NaN" as valid number anymore 2012-01-28 14:14:56 +01:00
Ivan Kurnosov
aaa9de6563 Added test case for checking that 'NaN' string converts into TransformationFailedException in NumberToLocalizedStringTransformer 2012-01-27 13:41:03 +13:00
Manuel Kiessling
6090deef90 [FormType] Adopted MoneyTypeTest::testMoneyPatternWorksForYen to CS 2012-01-26 15:43:25 +01:00
Manuel Kiessling
e814d273c2 [FormType] Fixed broken MoneyType regexp for JPY
The regexp in MoneyType doesn't work if currency format has no decimal
(like JPY) and doesn't work either if the currency symbol is unicode

This change fixes both issues and adds a unit test
2012-01-26 15:43:25 +01:00
Lars Strojny
746170bbe2 Make method non static 2012-01-25 14:56:27 +01:00
Lars Strojny
c3f637b834 PATCH support and tests for DELETE support 2012-01-25 14:54:48 +01:00
Victor Berchet
416a2a46df [Stopwatch] Fix some logic 2012-01-25 14:27:59 +01:00
Lars Strojny
2dd4bf1283 Support for PATCH method in forms 2012-01-24 19:46:37 +01:00
Jordi Boggiano
7f96c8ad17 [HttpKernel] Prevent php script execution in cached ESI pages using HttpCache 2012-01-24 19:27:21 +01:00
Bernhard Schussek
399af275ac [Form] Implemented checks to assert that values and indices generated in choice lists match their requirements 2012-01-24 12:21:25 +01:00
Victor Berchet
43e0db5f75 [DomCrawler] Add support for multivalued form fields (fix #1579, #3012) 2012-01-24 09:28:29 +01:00
Bernhard Schussek
f533ef0e1b [Form] Added ChoiceView class for passing choice-related data to the view 2012-01-24 01:07:33 +01:00
Bernhard Schussek
d72900e613 [Form] Incorporated changes suggested in PR comments 2012-01-23 18:58:56 +01:00
Bernhard Schussek
e1fc5a5c8c [Form] Restricted form names to specific characters to (1) fix generation of HTML IDs and to (2) avoid problems with property paths.
ad (1): HTML4 "id" attributes are limited to strings starting with a letter and containing only letters, digits, underscores, hyphens, periods and colons.

ad (2): Property paths contain three special characters needed for correct parsing: left/right bracket and period.

The rules for form naming are:

* Names may start with a letter, a digit or an underscore. Leading digits or underscores will be stripped from the "id" attributes.
* Names must only contain letters, digits, underscores, hyphens and colons.
* Root forms may have an empty name.

Solves #1919 and #3021 on a wider scope.
2012-01-23 18:28:25 +01:00
Bernhard Schussek
87b16e7015 [Form] Greatly improved ChoiceListInterface and all of its implementations
Fixes #2869, fixes #3021, fixes #1919, fixes #3153.
2012-01-23 18:28:25 +01:00
Christophe Coevoet
e37783f4f9 [DoctrineBridge] Refactored the query sanitization in the collector
The original parameters are kept whenever possible to allow using them
again to explain the query.
2012-01-23 10:57:46 +01:00
Christophe Coevoet
3b260d268b Refactored the collector to separate the loggers per connection 2012-01-23 09:22:30 +01:00
Fabien Potencier
3749355ba7 removed debug code 2012-01-22 17:21:04 +01:00
Fabien Potencier
35a61b3a52 [HttpKernel] added arguments to ExceptionHandler (closes #2739) 2012-01-22 16:53:27 +01:00
Fabien Potencier
63adb97cf2 Revert "merged branch blogsh/dynamic_constraints (PR #3114)"
This reverts commit 6b9a355fb0, reversing
changes made to 811ead8589.
2012-01-22 16:50:02 +01:00
Fabien Potencier
8d79ebc8ce [HttpKernel] added some unit tests for ExceptionHandler and
FlattenException
2012-01-22 11:19:40 +01:00
Fabien Potencier
8358cbf7a6 merged branch kriswallsmith/csrf-token-helper (PR #3080)
Commits
-------

753c067 [FrameworkBundle] added $view['form']->csrfToken() helper
e1aced8 [Twig] added {{ csrf_token() }} helper

Discussion
----------

[Twig] [FrameworkBundle] added CSRF token helper

I've added a templating helper and Twig function for generating a CSRF token without the overhead of creating a form.

```html+jinja
<form action="{{ path('user_delete', { 'id': user.id }) }}" method="post">
    <input type="hidden" name="_method" value="delete">
    <input type="hidden" name="_token" value="{{ csrf_token('delete_user_' ~ user.id) }}">
    <button type="submit">delete</button>
</form>
```

```php
<?php

class UserController extends Controller
{
    public function delete(User $user, Request $request)
    {
        $csrfProvider = $this->get('form.csrf_provider');
        if (!$csrfProvider->isCsrfTokenValid('delete_user_'.$user->getId(), $request->request->get('_token')) {
            throw new RuntimeException('CSRF attack detected.');
        }

        // etc...
    }
}
```

The test that is failing on Travis appears to be unrelated, but I may be wrong?

```
1) Symfony\Bundle\SecurityBundle\Tests\Functional\LocalizedRoutesAsPathTest::testLoginLogoutProcedure with data set #1 ('de')
RuntimeException: OUTPUT:
Catchable fatal error: Argument 3 passed to Symfony\Bundle\FrameworkBundle\Controller\TraceableControllerResolver::__construct() must be an instance of Symfony\Component\HttpKernel\Debug\Stopwatch, instance of Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser given, called in /tmp/2.1.0-DEV/StandardFormLogin/cache/securitybundletest/appSecuritybundletestDebugProjectContainer.php on line 94 and defined in /home/vagrant/builds/kriswallsmith/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/TraceableControllerResolver.php on line 37
```

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

by pablodip at 2012-01-10T14:18:45Z

As you don't need forms to use the csrf provider, how about putting its service without the form prefix? It could even make sense to put the CsrfProvider as a component since you can use it standalone and in more cases than only forms. It would be a small component though.

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

by Tobion at 2012-01-10T17:54:14Z

I think it would be more clear to generate the token in the controller. Doing so in the template will spread the CSRF intention across template and controller. So I don't think this extension is necessary.

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

by kriswallsmith at 2012-01-10T17:58:14Z

@pablodip I'm open to the idea of a Csrf component. This would be a good place for some nonce classes as well.

@Tobion I disagree. One use case is for a list of users, each with a delete form. Iterating over the users in the controller and generating a token for each, just to iterate over them again in the view is a waste and adds complexity.

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

by Tobion at 2012-01-10T18:05:14Z

I see. But I don't understand why the intention needs to be different for each user to delete. Usually the intention is the same for each form type. I thought this is enough.

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

by kriswallsmith at 2012-01-10T18:06:13Z

Yes, a static intention would suffice.

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

by Tobion at 2012-01-10T18:07:08Z

Then your use case is not valid anymore.

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

by Tobion at 2012-01-10T18:12:25Z

I would suggest to make a cookbook article out of it about how to create a simple form without the form component.
And include such things as validating the result using the validator component and checking the CSRF.

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

by kriswallsmith at 2012-01-10T21:32:50Z

This helper makes it easier to use CSRF protection without a form and we should make it as easy as possible. Spreading the intention across controller and template is not concerning to me. Either way, a cookbook entry is a great idea.

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

by Tobion at 2012-01-10T21:47:12Z

Well, it's just one line more without this helper. So I disagree it makes it really easier when you know how to use the CsrfProvider which is a pre-condition anyway since you must still validate its correctness by hand.

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

by kriswallsmith at 2012-01-13T13:24:15Z

Another use case is when rendering a page with a bunch of simple buttons with different intentions: delete user, delete comment, follow, unfollow... Creating all of these in the controller just leads to spaghetti.

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

by jwage at 2012-01-17T21:55:53Z

👍 lots of use cases for something like this @OpenSky
2012-01-22 10:31:29 +01:00
Fabien Potencier
6b9a355fb0 merged branch blogsh/dynamic_constraints (PR #3114)
Commits
-------

92f820a Renamed registerConstraints to loadDynamicValidatorMetadata
dd12ff8 CS fix, getConstraints renamed
09c1911 [Validator] Improved dynamic constraints
54cb6e4 [Validator] Added dynamic constraints

Discussion
----------

[Validator] Dynamic constraints

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes

By now the Validator component is based on a per-class configuration of
constraints, but in some cases it might be neccessary to add new constraints
dynamically at runtime.
This pull request adds a "ConstraintProviderInterface" to the Validator component. If an object is validated that implements this interface the method "getConstraints" is used to add dynamic constraints:

    class User implements ConstraintProviderInterface
    {
        protected $isPremium;
        protected $paymentInformation;

        public function getConstraints(ClassMetadata $metadata)
        {
            if ($this->isPremium) {
                $metadata->addPropertyConstraint('paymentInformation', new NotBlank());
            }
        }
    }

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

by alexandresalome at 2012-01-15T11:20:04Z

Related to #1151

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

by canni at 2012-01-16T09:22:28Z

👍

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

by bschussek at 2012-01-16T12:32:44Z

I think this is a good addition. I think we still have a naming problem though. When constraints are loaded using a static method, the default name for the loader method is `loadValidatorMetadata`. Since the method for dynamic constraint loading is basically the same, I think the two names should be related.

Solution (1): Rename the method in your interface to `loadDynamicValidatorMetadata`. Ugly and long.

    class MyClass implements ConstraintProviderInterface
    {
        public static loadValidatorMetadata(ClassMetadata $metadata) ...

        public loadDynamicValidatorMetadata(ClassMetadata $metadata) ...
    }

Solution (2): Rename the default method name in `StaticMethodLoader` to `registerConstraints` and adjust the docs. Breaks BC.

    class MyClass implements ConstraintProviderInterface
    {
        public static registerConstraints(ClassMetadata $metadata) ...

        public registerDynamicConstraints(ClassMetadata $metadata) ...
    }

@fabpot: Are we allowed to break BC here? If not, we should probably stick to (1).

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

by fabpot at 2012-01-16T12:36:14Z

I would prefer to not break BC if possible.

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

by blogsh at 2012-01-16T15:25:46Z

So "loadDynamicValidatorMetadata" would be the best solution?

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

by althaus at 2012-01-17T13:39:19Z

>So "loadDynamicValidatorMetadata" would be the best solution?

Sounds fine for me based on @bschussek's comment.
2012-01-22 10:26:39 +01:00
Fabien Potencier
811ead8589 [Serializer] fixed unit tests after previous merge + added a new one 2012-01-22 10:20:46 +01:00
Fabien Potencier
90fcbde685 merged branch canni/fix_cs (PR #3146)
Commits
-------

3cfaade [CS] Fix usage of assertCount

Discussion
----------

[CS] Fix usage of assertCount

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

[![Build Status](https://secure.travis-ci.org/canni/symfony.png)](http://travis-ci.org/canni/symfony)
2012-01-22 10:15:34 +01:00
Fabien Potencier
3c0b9c5b20 [DoctrineBridge] enhanced an error message (closes #3155) 2012-01-22 10:12:26 +01:00
Fabien Potencier
c7ec49c624 merged branch lstrojny/feature/form-http-delete (PR #3159)
Commits
-------

0b7e2e0 Support for DELETE method in forms

Discussion
----------

[Form] Support DELETE HTTP verb

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

As `Symfony\Component\HttpFoundation\Request` already support DELETE requests nicely by parsing the request for us, support for the HTTPs DELETE verb can be easily done.

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

by mvrhov at 2012-01-20T06:00:49Z

This is wrong. The body for DELETE method is supposed to be empty or if present ignored.
Also the DELETE is supposed to remove the resource identified by uri, so the same code as for GET should be executed.

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

by lstrojny at 2012-01-20T08:56:22Z

I don’t think that’s the case. The HTTP standard does not state explicitly that DELETE does not have a body. See this [StackOverflow thread](http://stackoverflow.com/questions/2539394/rest-http-delete-and-parameters)
2012-01-22 10:05:04 +01:00
Fabien Potencier
a5220313f6 Merge branch '2.0'
* 2.0:
  Updated Serbian translation.
  fixed CS
  [Locale][Testing] Fixed breaking tests if 'intl' extension is not installed (#3139)
  [Bridge] [Twig] fixed typo in a comment of the Twig FormExtension extension.
2012-01-22 07:33:58 +01:00
Lars Strojny
0b7e2e035a Support for DELETE method in forms 2012-01-20 01:04:31 +01:00
Sebastian Hörl
92f820a094 Renamed registerConstraints to loadDynamicValidatorMetadata 2012-01-18 22:24:42 +01:00
Dariusz Górecki
3cfaade8f7 [CS] Fix usage of assertCount
Bug fix: no
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: -
Todo: -
2012-01-18 14:42:47 +01:00
Manuel Kiessling
a1317c3437 [Locale][Testing] Fixed breaking tests if 'intl' extension is not installed (#3139)
Symfony\Tests\Component\Locale\LocaleTest->testGetDisplayCountriesReturnsFullListForSubLocale()
fails with a fatal error if the PHP extension 'intl' is not installed on the system.
Added a check which skips the affected tests if the extension is not available.
Fixes #3139
2012-01-17 18:44:55 +01:00
Fabien Potencier
e8f9a55012 fixed CS 2012-01-17 11:23:46 +01:00
Fabien Potencier
9c3c53a5c1 merged 2.0 2012-01-17 11:23:18 +01:00
Fabien Potencier
51ecb3c07b fixed CS 2012-01-17 10:56:02 +01:00
Fabien Potencier
733ac9de7a [HttpFoundation] fixed exception message (closes #3123) 2012-01-16 22:09:07 +01:00
Fabien Potencier
e056480ab2 merged branch bschussek/collection-validator (PR #3118)
Commits
-------

e6e3da5 [Validator] Improved test coverage of CollectionValidator and reduced test code duplication
509c7bf [Validator] Moved Optional and Required constraints to dedicated sub namespace.
bf59018 [Validator] Removed @api-tag from Optional and Required constraint, since these two are new.
6641f3e [Validator] Added constraints Optional and Required for the CollectionValidator

Discussion
----------

[Validator] Improve support for optional/required fields in Collection constraint

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

![Travis Build Status](https://secure.travis-ci.org/bschussek/symfony.png?branch=collection-validator)

Improves the `Collection` constraint to test on a more granular level if entries of the collection are optional or required. Before this could only be set using the "allowExtraFields" and "allowMissingFields" options, but these are very general and limited.

The former syntax - without Optional or Required - is still supported.

Usage:

    $array = array(
        'name' => 'Bernhard',
        'birthdate' => '1970-01-01',
    );
    $validator->validate($array, null, new Collection(array(
        'name' => new Required(),
        'birthdate' => new Optional(),
    ));

    // you can also pass additional constraints for the fields
    $validator->validate($array, null, new Collection(array(
        'name' => new Required(array(
            new Type('string'),
            new MinLength(3),
        )),
        'birthdate' => new Optional(new Date()),
    ));

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

by canni at 2012-01-15T20:22:17Z

@bschussek I've rewritten a lot of test code for Collection validator in 2.0 branch and also had modified validator itself, as it had a bug #3078, consider waiting with this PR till fabpot will merge 2.0 back into master, as there will be code conflicts :)

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

by Koc at 2012-01-15T23:13:04Z

Does it helps to #2615 ?

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

by fabpot at 2012-01-16T06:44:53Z

@canni: I've just merged 2.0 into master.

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

by bschussek at 2012-01-16T12:05:19Z

@fabpot: Rebased. I also fixed the CS issues mentioned by @stof.
2012-01-16 21:56:42 +01:00
Bernhard Schussek
0c70a410e5 [Form] Made validation of form children configurable. Set the option "cascade_validation" to true if you need it. 2012-01-16 20:49:43 +01:00
Manuel Kiessling
cacc880929 [Bugfix][Locale] Fixed incomplete Locale data loading
Sublocales like de_CH returned only incomplete results for
getDisplayCountries(), getDisplayLanguages() and getDisplayLocales(),
consisting only of results specific for this sublocale, but without the
results of their respective parent locale
2012-01-16 17:25:42 +01:00
Bernhard Schussek
e6e3da5063 [Validator] Improved test coverage of CollectionValidator and reduced test code duplication 2012-01-16 13:03:38 +01:00
Bernhard Schussek
509c7bfb5b [Validator] Moved Optional and Required constraints to dedicated sub namespace. 2012-01-16 11:30:56 +01:00
Bernhard Schussek
6641f3e231 [Validator] Added constraints Optional and Required for the CollectionValidator 2012-01-16 11:30:56 +01:00
Fabien Potencier
5fa0f2d92b merged 2.0 2012-01-16 07:44:08 +01:00
Sebastian Hörl
dd12ff836d CS fix, getConstraints renamed 2012-01-15 13:11:15 +01:00
Sebastian Hörl
09c191136a [Validator] Improved dynamic constraints 2012-01-14 02:24:14 +01:00
Sebastian Hörl
54cb6e458e [Validator] Added dynamic constraints 2012-01-14 02:06:07 +01:00
Fabien Potencier
741859dc47 merged branch canni/user_comparable_interface2 (PR #2927)
Commits
-------

e23d452 Add info about BC Break to CHANGELOG-2.1
d7ffeb5 Add some more tests, and enforce boolean return value of interface implementations.
9d3a49f When method name is `hasUserChanged` the return boolean should be true (to match question semantics) and false when user has not changed, this commits inverts return statements.
c57b528 Add note about `AdvancedUserInterface`.
3682f62 Refactor `isUserChanged` to `hasUserChanged`
56db4a1 Change names to Equatable
680b108 Suggested fixes ;)
9386583 [BC Break][Security] Moved user comparsion logic out of UserInterface As discussed on IRC meetings and in PR #2669 I came up with implementation. This is option2, I think more elegant.

Discussion
----------

[BC Break][Security][Option2] Moved user comparsion logic out of UserInterface

As discussed on IRC meetings and in PR #2669 I came up with implementation.
This is option2, I think more elegant.

BC break: yes
Feature addition: no/feature move
Symfony2 test pass: yes
Symfony2 test written: yes
Todo: decide about naming

[![Build Status](https://secure.travis-ci.org/canni/symfony.png)](http://travis-ci.org/canni/symfony)

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

by schmittjoh at 2011-12-19T19:33:24Z

This looks much better than the previous PR. Thanks!

One thing, we also discussed this on Doctrine, the name "comparable" is used in most programming languages to perform a real compare operation that is ">", "<", or "=". In this case though, we are specifically interested in equality of two objects (we cannot establish a natural order between these objects). Java has no such interface as all objects naturally have an equals() method, .NET uses "Equatable" which looks a bit odd. Not sure if there are better names.

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

by canni at 2011-12-19T19:34:52Z

I think this is best of "both worlds" we have nice full-featured implementation suitable for most, and if someone needs advanced compare logic just implements interface. @stof @schmittjoh, what do you think?

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

by stof at 2011-12-19T19:36:55Z

@canni I already commented on the code, and I agree with @schmittjoh that the naming can be confusing

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

by jmikola at 2011-12-20T17:33:22Z

I don't mean to bikeshed, but I strongly agree with @schmittjoh about implications of "compare". I'm not concerned with the interface name so much as I am with `compareUser()`. Given that this method returns a boolean, I think it's best to prefix it with `is` (e.g. `isSameUser`, `isUserEqualTo`) or `equals` (e.g. `equalsUser`).

In this PR, the Token class is implementing the interface, so I think having "User" in the method name is a good idea. Naturally, if the interface was intended for User classes, we could do without it.

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

by canni at 2011-12-20T19:00:00Z

@jmikola in this PR Token class does not implement any additional interface, and `compareUser` is `private` and used internally. I don't stand still after this names, I'll update PR as soon as some decision about naming will be done.

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

by jmikola at 2011-12-21T02:29:59Z

@canni: My mistake, I got confused between the Token method and interface method, which you've since renamed in canni/symfony@fcfcd1087b.

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

by mvrhov at 2011-12-21T06:09:45Z

hm. Now I'm going to bike shed. Wouldn't the proper function name be hasUserChanged?

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

by stof at 2011-12-21T10:58:38Z

it would probably be bettter. The meaning of ``true`` and ``false`` would then be the opposite of the current ones but this is not an issue IMO as it is a different method

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

by jstout24 at 2011-12-27T18:08:49Z

@canni nice job

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

by fabpot at 2011-12-30T14:59:11Z

The method `isUserChanged()` must be rename. What about `hasUserChanged()` as @mvrhov suggested or `isUserDifferent()`?

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

by canni at 2012-01-02T11:44:05Z

@fabpot done.

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

by fabpot at 2012-01-02T18:13:40Z

The only missing thing I can think of is adding some unit tests.

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

by canni at 2012-01-10T20:16:25Z

@fabpot is there anything more you think that should done in this PR?

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

by stof at 2012-01-10T20:38:46Z

@canni can you rebase your branch ? it conflicts with the current master according to github

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

by canni at 2012-01-10T20:56:55Z

@stof done.

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

by fabpot at 2012-01-12T18:06:00Z

@canni: Can you just add some information in the CHANGELOG and in the UPGRADE file? That's all I need to merge this PR now. Thanks a lot.

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

by canni at 2012-01-12T18:16:32Z

@fabpot done, and no problem :)
2012-01-12 19:26:40 +01:00
Victor Berchet
c0ad1ac170 [HttpKernel] Minor fixes in the Stopwatch 2012-01-10 22:23:16 +01:00
Dariusz Górecki
d7ffeb5844 Add some more tests, and enforce boolean return value of interface implementations. 2012-01-10 21:55:05 +01:00
Dariusz Górecki
9386583b19 [BC Break][Security] Moved user comparsion logic out of UserInterface
As discussed on IRC meetings and in PR #2669 I came up with implementation.
This is option2, I think more elegant.

BC break: yes
Feature addition: no/feature move
Symfony2 test pass: yes
Symfony2 test written: yes
Todo: feedback needed
2012-01-10 21:54:56 +01:00
Kris Wallsmith
e1aced89fd [Twig] added {{ csrf_token() }} helper 2012-01-10 05:16:32 -08:00
Dariusz Górecki
7f7c2a7094 Add prof-of-concept test, this test will fail without changes in previous commit 2012-01-10 11:51:28 +01:00
Andrej Hudec
747429341e memcache profiler storage support added
fix CS

fix CS + remove unneeded else

add documentation, change protected methods as private

rename var

throw exception for invalid name, index fix

memcache profiler storage support added, fix CS and minor bugs

fix CS

removed unneeded else

- memcached support added
- improved performance (serialization, index)

updated code to last version of Profiler
2012-01-10 00:33:54 +01:00
Jordi Boggiano
bea7a9c865 [Console] Fix tests on windows 2012-01-09 17:05:16 +01:00
Fabien Potencier
4ad7e0e4dd merged branch Seldaek/console_opts2 (PR #3061)
Commits
-------

c7ab9ba [Console] Allow redefinition of application options descriptions

Discussion
----------

[Console] Allow redefinition of application options descriptions

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes

This allows you to redefine an `InputOption` as long as it keeps the same semantic (same default, same name, same alias, same modes). There are two purposes:

- Modifying the description with a more accurate one
- Making sure the option appears in your commands' help

Concrete example: I often want to provide a verbose version of commands. It's an elegant and very common pattern, but I basically can't document what is going to happen if you do `--verbose` since the base Application already defines `--verbose`. Also the `--verbose` option does not appear when you do `console <command> --help`, which means people probably won't think of using that option.
2012-01-09 12:31:41 +01:00
Fabien Potencier
61975a1b3d [Console] tweaked previous merge 2012-01-09 12:22:03 +01:00
Fabien Potencier
4f8f2d4f47 merged branch Seldaek/console_opts (PR #3060)
Commits
-------

7f7b853 [Console] Format simple arrays nicer

Discussion
----------

[Console] Format simple arrays nicer

Minor cosmetic adjustment for simple (i.e. with sequential numeric keys) arrays
2012-01-09 12:15:01 +01:00
Fabien Potencier
ca8dc87940 merged 2.0 2012-01-09 11:51:30 +01:00
Jordi Boggiano
c9129e51fe Fix Console tests on windows 2012-01-09 10:04:20 +01:00
Tobias Schultze
17284937f6 made the assertions in the RequestTest more explicit and improved PHPDoc 2012-01-09 06:33:53 +01:00
Jordi Boggiano
c7ab9ba7ec [Console] Allow redefinition of application options descriptions 2012-01-09 00:42:35 +01:00
Jordi Boggiano
7f7b853d79 [Console] Format simple arrays nicer 2012-01-09 00:03:43 +01:00
Eric Clemmons
01fcb1bdd7 Updated GetSetMethodNormalizerTest to expect camelCased functions instead of lowercased 2012-01-08 13:55:41 -08:00
Fabien Potencier
561cde7743 merged branch digitalkaoz/bugfix_2730_v4 (PR #3052)
Commits
-------

9441c46 [DependencyInjection] PhpDumper, fixes #2730

Discussion
----------

[DependencyInjection] PhpDumper, fixes #2730

Hey, this PR fixes #2730, if no parameters are set, the constructor wont get passed a ParameterBag

Bug fix: yes (#2730)
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes

3rd and last try ;) this time i think its all fine
2012-01-07 16:41:16 +01:00
Dariusz Górecki
3702541b5a Add tests 2012-01-07 16:30:46 +01:00
Christophe Coevoet
9bc41d00d1 [HttpFoundation] Fixed #3053 2012-01-07 14:27:33 +01:00
digitalkaoz
9441c46bb6 [DependencyInjection] PhpDumper, fixes #2730 2012-01-06 21:20:08 +01:00
Victor Berchet
dcee6fffea [TwigBridge] Improve test coverage 2012-01-06 08:35:36 +01:00
stealth35
f4890c24f9 [Translation] Po/MoFileLoader parse plurization rules 2012-01-03 18:44:44 +01:00
Igor Wiedler
7ae93483f9 [streaming] Document and test that Transfer-Encoding is absent 2012-01-02 20:21:31 +01:00
Igor Wiedler
83c23ca0be [streaming] Do not set a Transfer-Encoding header of chunked
Apache expects the response to already be in chunked format in that case,
which causes it to not deliver the streamed body.

If no Content-Length is set on the response, web servers will automatically
switch to chunked Transfer-Encoding, and handle the chunking for you.

Nginx does not share the issue that apache has, but will add the Content-
Length header too.
2012-01-02 19:50:39 +01:00
Fabien Potencier
ce6399e254 [TwigBridge] added a way to specify a default domain for a Twig template (via the 'trans_default_domain' tag)
Note that the tag only influences the current templates. It has no effect on included files to avoid unwanted side-effects.
2012-01-02 17:48:19 +01:00
Fabien Potencier
6a052fb788 [TwigBridge] removed obsolete file 2012-01-02 17:48:16 +01:00
Fabien Potencier
c73e034229 [TwigBridge] added missing transchoice filters whe extracting translations from templates 2012-01-02 17:08:10 +01:00
Fabien Potencier
cadf3d4243 [HttpKernel] fixed doubled results for the file profiler (closes #2915) 2012-01-02 12:10:17 +01:00
Fabien Potencier
66a18f3239 [BrowserKit] first attempt at fixing CookieJar (closes #2209) 2011-12-31 16:32:51 +01:00
Fabien Potencier
716d002ef5 merged branch jmikola/MongoDbProfilerStorageTest (PR #3008)
Commits
-------

3ef0594 [HttpKernel] Fix missing $method argument in MongoDbProfilerStorageTest

Discussion
----------

[HttpKernel] Fix missing $method argument in MongoDbProfilerStorageTest

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

This test case fixes failures related to a signature change for ProfilerStorageInterface::find(). See: 1aef4e806b and 5f2226807c.

This was easily missed as the test case is skipped unless a MongoDB server is running.
2011-12-31 10:23:48 +01:00
Jeremy Mikola
3ef0594e74 [HttpKernel] Fix missing $method argument in MongoDbProfilerStorageTest
This test case fixes failures related to a signature change for ProfilerStorageInterface::find(). See: 1aef4e806b and 5f2226807c.
2011-12-31 03:10:55 -05:00
Fabien Potencier
899e252032 merged branch symfony/streaming (PR #2935)
Commits
-------

887c0e9 moved EngineInterface::stream() to a new StreamingEngineInterface to keep BC with 2.0
473741b added the possibility to change a StreamedResponse callback after its creation
8717d44 moved a test in the constructor
e44b8ba made some cosmetic changes
0038d1b [HttpFoundation] added support for streamed responses

Discussion
----------

[HttpFoundation] added support for streamed responses

To stream a Response, use the StreamedResponse class instead of the
standard Response class:

    $response = new StreamedResponse(function () {
        echo 'FOO';
    });

    $response = new StreamedResponse(function () {
        echo 'FOO';
    }, 200, array('Content-Type' => 'text/plain'));

As you can see, a StreamedResponse instance takes a PHP callback instead of
a string for the Response content. It's up to the developer to stream the
response content from the callback with standard PHP functions like echo.
You can also use flush() if needed.

From a controller, do something like this:

    $twig = $this->get('templating');

    return new StreamedResponse(function () use ($templating) {
        $templating->stream('BlogBundle:Annot:streamed.html.twig');
    }, 200, array('Content-Type' => 'text/html'));

If you are using the base controller, you can use the stream() method instead:

    return $this->stream('BlogBundle:Annot:streamed.html.twig');

You can stream an existing file by using the PHP built-in readfile() function:

    new StreamedResponse(function () use ($file) {
        readfile($file);
    }, 200, array('Content-Type' => 'image/png');

Read http://php.net/flush for more information about output buffering in PHP.

Note that you should do your best to move all expensive operations to
be "activated/evaluated/called" during template evaluation.

Templates
---------

If you are using Twig as a template engine, everything should work as
usual, even if are using template inheritance!

However, note that streaming is not supported for PHP templates. Support
is impossible by design (as the layout is rendered after the main content).

Exceptions
----------

Exceptions thrown during rendering will be rendered as usual except that
some content might have been rendered already.

Limitations
-----------

As the getContent() method always returns false for streamed Responses, some
event listeners won't work at all:

* Web debug toolbar is not available for such Responses (but the profiler works fine);
* ESI is not supported.

Also note that streamed responses cannot benefit from HTTP caching for obvious
reasons.

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

by Seldaek at 2011/12/21 06:34:13 -0800

Just an idea: what about exposing flush() to twig? Possibly in a way that it will not call it if the template is not streaming. That way you could always add a flush() after your </head> tag to make sure that goes out as fast as possible, but it wouldn't mess with non-streamed responses. Although it appears flush() doesn't affect output buffers, so I guess it doesn't need anything special.

When you say "ESI is not supported.", that means only the AppCache right? I don't see why this would affect Varnish, but then again as far as I know Varnish will buffer if ESI is used so the benefit of streaming there is non-existent.

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

by cordoval at 2011/12/21 08:04:21 -0800

wonder what the use case is for streaming a response, very interesting.

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

by johnkary at 2011/12/21 08:19:48 -0800

@cordoval Common use cases are present fairly well by this RailsCast video: http://railscasts.com/episodes/266-http-streaming

Essentially it allows faster fetching of web assets (JS, CSS, etc) located in the &lt;head>&lt;/head>, allowing those assets to be fetched as soon as possible before the remainder of the content body is computed and sent to the browser. The end goal is to improve page load speed.

There are other uses cases too like making large body content available quickly to the service consuming it. Think if you were monitoring a live feed of JSON data of newest Twitter comments.

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

by lsmith77 at 2011/12/21 08:54:35 -0800

How does this relate the limitations mentioned in:
http://yehudakatz.com/2010/09/07/automatic-flushing-the-rails-3-1-plan/

Am I right to understand that due to how twig works we are not really streaming the content pieces when we call render(), but instead the entire template with its layout is rendered and only then will we flush? or does it mean that the render call will work its way to the top level layout template and form then on it can send the content until it hits another block, which it then first renders before it continues to send the data?

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

by stof at 2011/12/21 09:02:53 -0800

@lsmith77 this is why the ``stream`` method calls ``display`` in Twig instead of ``render``. ``display`` uses echo to print the output of the template line by line (and blocks are simply method calls in the middle). Look at your compiled templates to see it (the ``doDisplay`` method)
Rendering a template with Twig simply use an output buffer around the rendering.

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

by fabpot at 2011/12/21 09:24:33 -0800

@lsmith77: We don't have the Rails problem thanks to Twig as the order of execution is the right one by default (the layout is executed first); it means that we can have the flush feature without any change to how the core works. As @stof mentioned, we are using `display`, not `render`, so we are streaming your templates for byte one.

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

by fabpot at 2011/12/21 09:36:41 -0800

@Seldaek: yes, I meant ESI with the PHP reverse proxy.

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

by fabpot at 2011/12/21 09:37:34 -0800

@Seldaek: I have `flush()` support for Twig on my todo-list. As you mentioned, It should be trivial to implement.

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

by fzaninotto at 2011/12/21 09:48:18 -0800

How do streaming responses deal with assets that must be called in the head, but are declared in the body?

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

by fabpot at 2011/12/21 09:52:12 -0800

@fzaninotto: What do you mean?

With Twig, your layout is defined with blocks ("holes"). These blocks are overridden by child templates, but evaluated as they are encountered in the layout. So, everything works as expected.

As noted in the commit message, this does not work with PHP templates for the problems mentioned in the Rails post (as the order of execution is not the right one -- the child template is first evaluated and then the layout).

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

by fzaninotto at 2011/12/21 10:07:35 -0800

I was referring to using Assetic. Not sure if this compiles to Twig the same way as javascript and stylesheet blocks placed in the head - and therefore executed in the right way.

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

by fabpot at 2011/12/21 10:34:59 -0800

@Seldaek: I've just added a `flush` tag in Twig 1.5: 1d6dfad4f5

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

by catchamonkey at 2011/12/21 13:29:22 -0800

I'm really happy you've got this into the core, it's a great feature to have! Good work.
2011-12-31 08:12:02 +01:00
Fabien Potencier
d12f5b202c [Routing] removed trailing slash support for routes that are not available for GET/HEAD methods (as the redirection will always occurs with a GET/HEAD request, closes #2626) 2011-12-30 19:30:23 +01:00
Fabien Potencier
7b00662df3 [Routing] fixed wrong namespaces in tests 2011-12-30 19:13:17 +01:00
Fabien Potencier
a78437bba9 Revert "merged branch kriswallsmith/security/demeter-fix (PR #2816)"
This reverts commit 76ba2bc7ac, reversing
changes made to 4730f4303b.
2011-12-30 16:05:26 +01:00
Fabien Potencier
466a8b8f48 Merge branch '2.0'
* 2.0:
  [Tests] Skip segfaulting form test
  Rename test file
  [BrowserKit] added missing @return PHPDoc for the Client::submit() method.
  also test PHP 5.3.2, since this is the official lowest supported PHP version
2011-12-30 15:44:05 +01:00
Joseph Bielawski
4c44023e8b [Tests] Skip segfaulting form test 2011-12-30 15:36:55 +01:00
Olivier Dolbeau
0d3e709e0e Rename test file 2011-12-29 16:30:31 +01:00
Fabien Potencier
23e04e3acb merged 2.0 2011-12-29 09:22:11 +01:00
Bart van den Burg
ced57d8ee5 reverse transform doesn't take a second argument 2011-12-29 09:10:04 +01:00
mlively
601d462589 [Form] Added getValidators() to Form class 2011-12-28 12:47:11 -08:00
Fabien Potencier
a01eee8536 merged branch ericclemmons/2884-parameterbag-with-spaces (PR #2976)
Commits
-------

85ca8e3 ParameterBag no longer resolves parameters that have spaces.
99011ca Added tests for ParameterBag parameters with spaces

Discussion
----------

[DependencyInjection] Parameters with spaces are not resolved

Bug fix: yes
Feature addition: no
Backwards compatibility break: no (not likely, according to convention)
Symfony2 tests pass: yes
Fixes the following tickets: #2884

`ParameterBag` currently resolves anything between two `%` signs, which creates issues for any parameters in the DIC that are legitimate text.  This PR enforces the [documented parameter convention](http://symfony.com/doc/2.0/book/service_container.html#service-parameters) so that only `%parameters.with.no_spaces%` are resolved.

I was considering using instead `^%([^\w\._-]+)%$`, but felt that was too constricting & could easily introduce issues with existing applications.
2011-12-28 21:36:04 +01:00
Fabien Potencier
cab70f4083 merged 2.0 2011-12-28 20:44:29 +01:00
Javier Eguíluz
3f2e1b0483 [Console] Updated tests to reflect the change from program to application 2011-12-28 12:44:00 +01:00
Eric Clemmons
99011ca9c9 Added tests for ParameterBag parameters with spaces 2011-12-27 12:48:49 -08:00
Fabien Potencier
f579f72b32 [HttpKernel] added a unit test for previous merge 2011-12-26 22:32:11 +01:00
Drak
79793e442a Coding standards and removing whitespace. 2011-12-24 15:50:47 +05:45
Joseph Bielawski
9daa2a6cc8 [Profiler] Add function to get parent token directly 2011-12-23 09:45:13 +01:00
Fabien Potencier
5b2bc7d7f9 merged 2.0 2011-12-23 08:57:06 +01:00
Christophe Coevoet
373ab4c50f Fixed tests added from 2.0 2011-12-22 17:52:42 +01:00
Christophe Coevoet
24319bb0f4 [DoctrineBridge] Made it possible to change the manager used by the provider 2011-12-22 16:14:12 +01:00
Bart van den Burg
c60f0363de fixed typo 2011-12-22 10:57:47 +01:00
Bart van den Burg
231e79ce0f fixed entity choice list BC break 2011-12-22 10:49:27 +01:00
Fabien Potencier
0fa9e4cb69 [HttpKernel] fixed some unit tests that can fail 2011-12-22 08:06:15 +01:00