Commit Graph

2291 Commits

Author SHA1 Message Date
Fabien Potencier
afdecaf542 [HttpFoundation] fixed a test 2012-03-23 18:01:05 +01:00
Fabien Potencier
09ab6430c0 merged branch drak/session_flashmessages (PR #3267)
Commits
-------

5ae76f1 [HttpFoundation] Update documentation.
910b5c7 [HttpFoudation] CS, more tests and some optimization.
b0466e8 [HttpFoundation] Refactored BC Session class methods.
84c2e3c [HttpFoundation] Allow flash messages to have multiple messages per type.

Discussion
----------

[2.1][HttpFoundation] Multiple session flash messages

Bug fix: no
Feature addition: yes
Backwards compatibility break: yes, but this already happened in #2583.  BC `Session` methods remain unbroken.
Symfony2 tests pass: yes
Fixes the following tickets: #1863
References the following tickets: #2714, #2753, #2510, #2543, #2853
Todo: -

This PR alters flash messages so that it is possible to store more than one message per flash type using the `add()` method or by passing an array of messages to `set()`.

__NOTES ABOUT BC__

This PR maintains BC behaviour with the `Session` class in that the old Symfony 2.0 methods will continue to work as before.

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

by drak at 2012-02-13T06:28:33Z

I think this is ready for review @fabpot @lsmith77

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

by lsmith77 at 2012-02-14T19:30:39Z

the FlashBag vs. AutoExpireFlashBag behavior and setup difference should probably also be explained in the upgrading log

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

by drak at 2012-02-15T04:43:14Z

@lsmith77 Those differences are explained already in the changelog

 * Added `FlashBag`. Flashes expire when retrieved by `get()` or `all()`.
   This makes the implementation ESI compatible.
 * Added `AutoExpireFlashBag` (default) to replicate Symfony 2.0.x auto expire behaviour of messages auto expiring
   after one page page load.  Messages must be retrived by `get()` or `all()`.

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

by Crell at 2012-02-19T17:35:34Z

Drak asked me to weigh in here with use cases.  Drupal currently has a similar session-stored-messaging system in place that I'd like to be able to replace with Flash messages.  We frequently have multiple messages within a single request, however, so this change is critical to our being able to do so.

For instance, when saving an article in Drupal there is, by default, a "yay, you saved an article!" type message that gets displayed.  If you also have the site configured to send email when a post is updated, you may see a "email notifications sent" message (depending on your access level).  If you have a Solr server setup for search, and you're in debug mode, there will also be a "record ID X added to Solr, it should update in 2 minutes" message.  And if there's a bug somewhere, you'll also get, as an error message rather than notice message, a "Oops, E_NOTICE on line 54" message.

Form validation is another case.  If you have multiple errors in a single form, we prefer to list all of them.  So if you screw up 4 times on a form, you may get 4 different error messages showing what you screwed up so you can fix it in one go instead of several.

Now sure, one could emulate that by building a multi-message layer on top of single-layer messages, but, really, why?  "One is a special case of many", and there are many many cases where you'll want to post multiple messages.  Like, most of Drupal. :-)

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

by lsmith77 at 2012-03-06T20:55:51Z

@fabpot is there any information you still need before merging this? do you want more discussion in which case you might want to take this to the mailing list ..

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

by drak at 2012-03-08T18:54:13Z

Another plus for this PR is that it requires no extra lines of code in templates etc to display the flashes, see https://github.com/symfony/symfony/pull/3267/files#diff-1

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

by drak at 2012-03-15T06:38:21Z

Rebased against current `master`, should be mergeable again..

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

by evillemez at 2012-03-17T03:08:41Z

+1 to this, I have an extended version of HttpFoundation just for this... would love to get rid of it.
2012-03-23 17:58:09 +01:00
Fabien Potencier
30cd43c68a fixed CS 2012-03-23 14:14:07 +01:00
Fabien Potencier
6381dbb8ed merged branch cboden/interfaces (PR #3520)
Commits
-------

bd02554 [HttpFoundation] SPL IteratorAggregate+Countable on *Bags
665fdeb [HttpFoundation] SPL on ParameterBag

Discussion
----------

[HttpFoundation] SPL on ParameterBag

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

Added a couple SPL interfaces to ParameterBag, added shortcuts to working with the parameters.  For example:

```php
<?php
    $post = Request::createFromGlobal()->request;
    echo "There are {count($post)} POST variables\n";

    foreach ($post as $key => $val) {
        echo "{$key}: {$val}\n";
    }
```

Thoughts?

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

by stealth35 at 2012-03-07T13:09:11Z

You already have the `all` method

``` php
<?php
$post = Request::createFromGlobals()->request->all();

echo "There are ", count($post), " POST variables\n";

foreach ($post as $key => $val) {
    echo "{$key}: {$val}\n";
}
```

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

by cboden at 2012-03-07T13:50:22Z

Yes, but when in the context of working with the Request object (or POST ParamegerBag), it's 1 more call and loose variable to set.

ParameterBag is a container, these common SPL interfaces give standard PHP container methods to it.

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

by lsmith77 at 2012-03-07T18:42:41Z

makes sense to me ..

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

by vicb at 2012-03-09T15:45:40Z

Probably makes sense. Could you check if any other `*Bag.php` needs to be updated so that it could ba an atomic merge.

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

by cboden at 2012-03-09T15:48:40Z

Whoops, good catch @vicb.  I made a poor assumption all the *Bags extended ParameterBag, while only some do.  I will post an update shortly.
2012-03-23 13:44:35 +01:00
Fabien Potencier
14a83ce064 merged branch pulzarraider/redis_session_storage (PR #3498)
Commits
-------

c4ee947 Native Redis Session Storage update
665f593 NativeRedisSessionStorage added

Discussion
----------

[HttpFoundation] Native Redis Session Storage

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

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

by lstrojny at 2012-03-04T23:15:43Z

Does Symfony (or any of its dependencies) has Redis support in any form whatsoever? If not this might be a good point to decide which clients to support

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

by lsmith77 at 2012-03-04T23:36:11Z

well ideally we just get this cache interface stuff done .. for this use case it would be perfect.

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

by pulzarraider at 2012-03-05T00:35:59Z

There is RedisProfilerStorage available (based on phpredis). I prefer and write code for [phpredis](https://github.com/nicolasff/phpredis).

It's recommended by [official Redis homepage](http://redis.io/clients#PHP). [In this benchmark](http://dev.af83.com/2011/01/01/which-php-library-to-use-with-redis-the-benchmark.html
) is fastest and less memory consumpting.

But if somebody prefer predis (with phpiredis), rediska or something other widely used, there are no limitations to add support of it to Symfony.

My opinion is, that the C extension should be supported at first, because of good performance and native session storage support. Redis is quite young and the process of creating PHP clients is comparable to Memcache.
There were created pure PHP Memcache clients in the past (Google found for example [this](http://www.phpclasses.org/browse/file/20284.html) and [this](http://code.blitzaffe.com/pages/phpclasses/files/memcached_client_52-12)), but they are not being used now. Everyone, who is seriously thinking about performance, is using only the C Redis/Memcache(d)/... extensions.

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

by drak at 2012-03-05T07:40:06Z

+1 on this PR.  Needs a test written though.
I don't think there is any need to wait for #3493 imo.  I'll deal with it if this is merged before #3493.
Are there any PHP ini settings for this for this driver or is everything via the `session.save_path` directive? (A quick look at the C code seems to indicate there are no explicit ini directives).

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

by lstrojny at 2012-03-05T12:14:34Z

@pulzarraider I don’t necessarily disagree with the usage of phpredis, I just wanted to bring up the issues of various clients and people having different preferences about them.

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

by fabpot at 2012-03-05T14:46:22Z

@pulzarraider Can you add some unit tests before I merge?

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

by pulzarraider at 2012-03-11T20:19:57Z

@drak No there are no php.ini settings. Only RedisArray has some, but it's another feature.

@fabpot I've added simple test based on other session storage tests.

I planned to create a RedisSessionStorage, too, but I have no time for it now. This can be added later in another PR as it's independent from NativeRedisSessionStorage.

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

by drak at 2012-03-12T02:21:25Z

The code looks OK to me.

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

by fabpot at 2012-03-15T06:05:27Z

#3493 has been merged now.

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

by pulzarraider at 2012-03-16T23:21:27Z

Code updated.
2012-03-23 13:42:58 +01:00
Fabien Potencier
43c01bc543 [Process] renamed waitForTermination() to wait() 2012-03-23 13:03:51 +01:00
Fabien Potencier
2be7c66d3a [Process] fixed CS 2012-03-23 13:03:47 +01:00
drak3
af65673363 [Process] Added support for non-blocking process control
Added methods to control long running processes to the Process class:
 - A non blocking start method to startup a process and return
   immediately
 - A blocking waitForTermination method to wait for the processes
   termination
 - A stop method to stop a process started with start
All status-getters like getOutput were changed to return real-time data
2012-03-23 11:12:57 +01:00
Fabien Potencier
26c9cb787e merged branch havvg/feature/jsonp-response (PR #3639)
Commits
-------

4a43453 remove callback from constructor and create method
601b87c add basic validation of callback name
266f76d rename jsonp to callback, defaults to null
38b79a7 add data and callback setter to JsonResponse
6788224 add JSONP support to JsonResponse

Discussion
----------

add JSONP support to JsonResponse

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

by schmittjoh at 2012-03-19T17:56:24Z

I think a ``setCallback()`` method would be more expressive, and easier to use:

```php
<?php

return JsonResponse::create($myData)->setCallback('foo');
// vs
return new JsonResponse($myData, 200, array(), 'foo');
```

What do you think?

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

by havvg at 2012-03-19T18:07:38Z

Looks good to me, I'll add it.

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

by dlsniper at 2012-03-19T19:38:45Z

+1 for this one :)

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

by vicb at 2012-03-19T23:09:50Z

Sorry for nitpicking but what about:

* some validation on the function name ?
* renamming `jsonp` -> `callback` ?

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

by havvg at 2012-03-20T09:16:32Z

@vicb What do you mean with "some validation on the function name"? I can't follow you there.

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

by vicb at 2012-03-20T09:22:49Z

I mean a valid JS function name

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

by havvg at 2012-03-20T09:34:59Z

Ah I see, I searched for it, and ended up with those results:

* The most complete: http://stackoverflow.com/questions/2008279/validate-a-javascript-function-name#answer-9392578
* and a less accurate one: http://www.geekality.net/2011/08/03/valid-javascript-identifier/

I'm not sure whether to put this into the `JsonResponse` itself, or to add somewhere else (where, if so?).

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

by vicb at 2012-03-20T09:45:20Z

I would go for a regexp only (ignoring reserved words); The idea would be not to use this to run arbitrary JS code.

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

by fabpot at 2012-03-21T21:33:36Z

Now that you have added the `setCallback` method, I would remove the constructor argument as it makes the signature quite long. As we have the `create` method anyway, it's more explicit and clearer to use the `setCallback` .

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

by havvg at 2012-03-21T21:37:51Z

So remove the callback argument from both, the constructor and the `create` method or only from the constructor?

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

by havvg at 2012-03-21T21:38:30Z

Ehr.. never mind :-)
2012-03-22 00:10:35 +01:00
Toni Uebernickel
4a43453db8 remove callback from constructor and create method 2012-03-21 22:40:39 +01:00
Fabien Potencier
72b9793940 fixed previous merge 2012-03-21 22:35:06 +01:00
Fabien Potencier
0ad71a07e8 merged branch rdohms/upload-validation-details (PR #3637)
Commits
-------

836d12b Fixing typo.
ac2a187 Improved feedback for Upload Validator to cover all PHP error states. This way we don't get a unclear "upload error" message unless its something completely unexpected.

Discussion
----------

Improved feedback for Upload Validator to cover all PHP error states.

The upload validator only sets individual messages for 2 out of the 7 error states PHP suports for uploading files. Which means when you have any of those 5 stats you get a standard error message and have to really dig into the code to read the error state.

I added messages for every state, so that you will always get a detailed message.

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

by stloyd at 2012-03-19T13:54:04Z

You should probably also extend translations in `FrameworkBundle`.

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

by rdohms at 2012-03-19T14:04:50Z

@stloyd what's the best way to do that? I obviously don't speak all languages. Could you point me to a best practices in this case?

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

by stof at 2012-03-19T15:58:17Z

@rdohms update the translations for the languages you speak. Other people will contribute with update later eventually :)

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

by rdohms at 2012-03-19T22:34:50Z

Fixed the typo, only other language i can update is portuguese, but it needs more work. I'll update it on a separate PR later on.

Anything else for this PR?

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

by mvrhov at 2012-03-20T05:41:00Z

@rdohms: just put English strings into other lanugages

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

by rdohms at 2012-03-20T07:35:56Z

@mvrhov is there a quick way to do this? or is it copying and pasting into every language and adjusting the string IDs?

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

by mvrhov at 2012-03-20T09:02:59Z

AFAIK you'll have to copy paste. String ids and source are the same in all translations so it really is just c/p after you update the first one.

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

by rdohms at 2012-03-20T09:56:48Z

@mvrhov so which is the most updated one you would say? i see a lot of them missing bit and pieces :P

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

by mvrhov at 2012-03-20T14:00:21Z

Sorry no idea.

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

by stof at 2012-03-20T19:09:10Z

@mvrhov Please don't do this. The translation component has a fallback mecanism so putting the EN string in an incomplete translation file is a bad idea as it forbids using a fallback.

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

by rdohms at 2012-03-20T20:14:50Z

@stof i figured as much.

Any other concerns before we push this PR further?
2012-03-21 22:31:15 +01:00
Fabien Potencier
e83f5f4f03 merged branch aerialls/xliff_fix (PR #3664)
Commits
-------

93d2a4f [Translation] Ignore xliff entries with no "target" node

Discussion
----------

[Translation] Ignore xliff entries with no "target" node

This PR will ignore some entries with no "target" node when a xliff file is loaded.

```xml
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
  <file source-language="en" datatype="plaintext" original="file.ext">
    <body>
      <trans-unit id="1">
        <source>foo</source>
        <target>bar</target>
      </trans-unit>
      <trans-unit id="2">
        <source>extra</source>
      </trans-unit>
    </body>
  </file>
</xliff>
```
Before:

```php
array(
    'foo'   => 'bar',
    'extra' => ''
);
```

After:

```php
array(
    'foo' => 'bar'
);
```

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

by fabpot at 2012-03-21T17:35:51Z

Wouldn't it be better to throw an exception for such cases? A `trans-unit` without a `target` is useless anyway, no?

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

by aerialls at 2012-03-21T20:25:19Z

I'm using transifex (https://www.transifex.net/home/) and when a user doesn't translate an entry, transifex fills up a `trans-unit` node without a `target` children.
2012-03-21 22:27:33 +01:00
Julien Brochet
93d2a4f039 [Translation] Ignore xliff entries with no "target" node 2012-03-21 14:55:53 +01:00
Tobias Schultze
447d46814c restore previous testing style with static fixtures for console 2012-03-21 05:32:53 +01:00
Tobias Schultze
11585c3b67 fix Command:asXml to use processed help 2012-03-21 05:32:51 +01:00
Tobias Schultze
304e13daa3 replaced command names with supported placeholders in help texts 2012-03-21 05:31:52 +01:00
Fabien Potencier
69fc07a21c merged branch vicb/routing_cleanup (PR #3647)
Commits
-------

a8e17fe [Routing] Cleanup

Discussion
----------

[Routing] Cleanup

removing the obsolete `segment_separators` option
2012-03-21 00:33:54 +01:00
Victor Berchet
979c02ba1f [HttpKernel] Fix MongoDbProfilerStorageTest 2012-03-20 17:56:45 +01:00
Toni Uebernickel
601b87ca01 add basic validation of callback name 2012-03-20 11:05:22 +01:00
Victor Berchet
a8e17fe45b [Routing] Cleanup 2012-03-20 09:12:35 +01:00
Toni Uebernickel
38b79a7023 add data and callback setter to JsonResponse 2012-03-19 19:40:54 +01:00
Toni Uebernickel
678822459b add JSONP support to JsonResponse 2012-03-19 18:29:39 +01:00
Rafael Dohms
ac2a187b4d Improved feedback for Upload Validator to cover all PHP error states.
This way we don't get a unclear "upload error" message unless its something completely unexpected.
2012-03-19 14:37:25 +01:00
Fabien Potencier
645d09c984 merged branch jmikola/double-dash (PR #3624)
Commits
-------

4d4ef24 [Console] Stop parsing options after encountering "--" token

Discussion
----------

[Console] Stop parsing options after encountering "--" token

This enables support for arguments with leading dashes (e.g. "-1"), as supported by getopt in other languages.

[![Build Status](https://secure.travis-ci.org/jmikola/symfony.png?branch=double-dash)](http://travis-ci.org/jmikola/symfony)

The test suite currently fails due to 7a54fe41ca. ArgvInputTest passes, and these changes don't appear to break anything else.

![](http://media.giantbomb.com/uploads/2/27528/1061704-mario_kart_double_dash___title_screen_super.jpg)

Aside: This got me thinking about how one would pass an option value of "-1". I suppose for input options with `VALUE_OPTIONAL`, it would be ambiguous if "-1" followed; however, `VALUE_REQUIRED` should probably require that the next token is captured as the option value. In my tests, a required option value with a leading dash was interpreted as another option. The workaround for all of this is to use the space-less syntax (e.g. `-f=-1`).

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

by fabpot at 2012-03-17T08:43:15Z

AFAIK, the `--` should disable both option and argument parsing, no?

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

by jmikola at 2012-03-18T02:13:51Z

If that were the case, what would be the point of using `--` at all? :)

 * http://wiki.bash-hackers.org/dict/terms/end_of_options
 * http://perldoc.perl.org/Getopt/Long.html#Mixing-command-line-option-with-other-arguments
2012-03-19 00:28:49 +01:00
Andrej Hudec
f351cdc52c doc fix 2012-03-17 00:59:57 +01:00
Andrej Hudec
c4ee947a83 Native Redis Session Storage update 2012-03-17 00:17:36 +01:00
Andrej Hudec
665f59348b NativeRedisSessionStorage added
- fix and simple unit test added
2012-03-17 00:17:33 +01:00
Jeremy Mikola
4d4ef24c47 [Console] Stop parsing options after encountering "--" token
This enables support for arguments with leading dashes (e.g. "-1"), as supported by getopt in other languages.
2012-03-16 15:53:13 -04:00
Chris Boden
bd02554289 [HttpFoundation] SPL IteratorAggregate+Countable on *Bags
Added the IteratorAggregate and Countable SPL Interfaces on all the *Bag classes in HttpFoundation
2012-03-15 16:41:06 -04:00
Fabien Potencier
5631002cd0 merged branch Seldaek/chainableresp (PR #3606)
Commits
-------

3297f75 Fix header override
076bd1e [HttpFoundation] Add create on StreamedResponse

Discussion
----------

Chainable response

Fixed feedback from #3605
2012-03-15 19:10:35 +01:00
Jordi Boggiano
076bd1e99f [HttpFoundation] Add create on StreamedResponse 2012-03-15 18:40:15 +01:00
Fabien Potencier
0ba5096fe6 fixed CS 2012-03-15 17:42:47 +01:00
Fabien Potencier
4c5c7bc91e merged branch Seldaek/chainableresp (PR #3605)
Commits
-------

ff13528 [HttpFoundation] Add create method to Json & Redirect responses
1c86ad7 [HttpFoundation] Add headers arg to RedirectResponse
873da43 [HttpFoundation] Add chainability to the Response class

Discussion
----------

Chainable responses

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

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

by cboden at 2012-03-15T15:53:43Z

+1
2012-03-15 17:39:12 +01:00
Fabien Potencier
120c2a260f merged branch vicb/twig/form_theme (PR #3576)
Commits
-------

0c83c5d [Form] Alternate syntax for form_theme

Discussion
----------

[RFC][Form] Alternate syntax for form_theme

before
`{% form_theme form _self "::base.html.twig" %}`

after
`{% form_theme form with "::base.html.twig" %}`
`{% form_theme form with varTheme %}`
`{% form_theme form with [_self, "::base.html.twig"] %}`

_the former syntax is still supported_

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

by stof at 2012-03-12T15:42:32Z

do you really need ``with`` ?

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

by vicb at 2012-03-12T15:50:41Z

it's not needed but I find it more clear (It can be drop if a consensus is reached)

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

by fabpot at 2012-03-12T17:05:46Z

+1 for `with`. Documentation for master should be updated as well.

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

by Tobion at 2012-03-13T02:26:22Z

+1 for `with`, but the syntax without array like `{% form_theme form with "::base.html.twig" %}` should also be supported

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

by vicb at 2012-03-13T07:16:55Z

`[]` are nice as they clearly indicate the ability to use multiple themes (which I think is yet to be documented). We'll pick the most popular syntax only.

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

by stof at 2012-03-13T08:16:40Z

@vicb supporting a string instead of an array should be possible when you need only one element. supporting several ones and turning it into an array is the mistake we made for 2.0

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

by hhamon at 2012-03-13T08:16:45Z

+1 for the new syntax

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

by vicb at 2012-03-13T08:29:45Z

@stof @Tobion what about using the former syntax then ?

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

by Baachi at 2012-03-13T08:32:09Z

+1 for new syntax. But it should be possible to use strings instead of arrays.

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

by stof at 2012-03-13T08:33:07Z

@vicb Having one wyntax using ``with`` and the other without will confuse users IMO. this is why I suggested allowing to pass a Twig array without adding an extra word

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

by stof at 2012-03-13T08:40:02Z

@Baachi not stringS as it is precisely what we are trying to solve :)

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

by Baachi at 2012-03-13T08:42:03Z

Oh sry. I mean __string__. :)

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

by fabpot at 2012-03-13T11:16:30Z

+1 for supporting a string or an array with the new syntax as using only one element is probably the most common use case. But then, why not supporting any valid Twig expression?

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

by vicb at 2012-03-13T11:54:51Z

Something like the latest commit ? (Tests have to be updated).

@fabpot What is the best place to handle array / non-array ? This is currenlty handled in the node but the parser might be a better place.

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

by fabpot at 2012-03-13T13:23:08Z

@vicb: I would just remove the special array case in the node as it's not needed anymore.

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

by fabpot at 2012-03-13T13:24:15Z

... and update FormExtension::setTheme() to also accept a string in which case we convert it to an array there.

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

by schmittjoh at 2012-03-13T14:26:17Z

I'd prefer a named argument instead of an ubiquitous "with" keyword which does not really tell me what's coming next.

Something like ``{% form_theme _form templates=[a, b, c] %}``. This is pretty nicely done for the assetic tags "javascripts", and "stylesheets".

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

by Tobion at 2012-03-13T16:04:26Z

@schmittjoh it would only make sense if there are multiple named arguments. With only one available it seems redundant.
Also `{% form_theme _form templates="template.html.twig" %}` is bad.

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

by vicb at 2012-03-14T07:59:08Z

I tend to agree with @Tobion but I'll have a closer look at assetic to see if we can make things more consistent.

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

by Seldaek at 2012-03-14T10:36:15Z

This would be more consistent with assetic, but assetic isn't really consistent with anything else in twig, although I see the benefits in that particular case for swapping and omitting parameters.

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

by schmittjoh at 2012-03-14T15:49:37Z

My goal was not really consistency, but I simply find it more obvious,
self-explanatory and easier to understand if you name things explicitly. We
are using the "with" keyword in several places and each time something
different is expected.

To me explicit naming is superior, but just my 2c

On Wed, Mar 14, 2012 at 4:36 AM, Jordi Boggiano <
reply@reply.github.com
> wrote:

> This would be more consistent with assetic, but assetic isn't really
> consistent with anything else in twig, although I see the benefits in that
> particular case for swapping and omitting parameters.
>
> ---
> Reply to this email directly or view it on GitHub:
> https://github.com/symfony/symfony/pull/3576#issuecomment-4495732
>

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

by Tobion at 2012-03-14T16:48:01Z

When I first saw this tag I didn't understand the role of first parameter.
So if we use johannes suggestion it should rather be `{% form_theme form=myForm templates=[a, b, c] %}`

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

by mvrhov at 2012-03-14T18:09:09Z

Before we complicate this any further can I add another thing here.
Moving to dedicated issue: Inflexible form theming #3598

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

by vicb at 2012-03-14T18:20:54Z

@mvrhov that is not the good place to discuss this (both this particular issue and GH as this is a support request).

_Have you tried `{% form_theme form.subForm ... %}`_

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

by vicb at 2012-03-15T07:39:14Z

Where do you think we should go:

1. `{% form_theme form with [_self, "::base.html.twig"] %}`
2. `{% form_theme form=form src=[_self, "::base.html.twig"] %}`

Let's discuss the structure first & not the details (i.e. src vs templates).

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

by Baachi at 2012-03-15T07:52:51Z

I tend to ```{% form_theme form with [_self, "::base.html.twig"] %}```, because its more consistent to the twig syntax.

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

by fabpot at 2012-03-15T13:10:56Z

@vicb: I like 1) more than 2) as this how the built-in tags work.

To keep BC even further, can we just remove the `with` keyword? To make it BC, we just need to have a look at extra parameters and add it to an array if they exist.

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

by Tobion at 2012-03-15T13:19:52Z

For newcomers 2) is definitely easier to understand. But it would also only make sense if you can change the parameter order, so `{% form_theme form=form src=[_self, "::base.html.twig"] %}` == ` {% form_theme src=[_self, "::base.html.twig"] form=form %}`. At the same time it reduces consistency. So for experienced developers option 1) [without "with"] is less redundant and preferable.

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

by vicb at 2012-03-15T13:53:49Z

@fabpot removing the `with` will make `Parser::parsePostfixException()` scream when providing an array of themes.
2012-03-15 16:54:08 +01:00
Jordi Boggiano
ff13528ad0 [HttpFoundation] Add create method to Json & Redirect responses 2012-03-15 16:28:15 +01:00
Jordi Boggiano
873da434cd [HttpFoundation] Add chainability to the Response class 2012-03-15 16:27:06 +01:00
Fabien Potencier
7a54fe41ca merged 2.0 2012-03-15 15:47:03 +01:00
Fabien Potencier
bbd686a685 merged branch igorw/json-response (PR #3375)
Commits
-------

5fa1c70 [json-response] Add a JsonResponse class for convenient JSON encoding

Discussion
----------

[json-response] Add a JsonResponse class for convenient JSON encoding

Usage example:

    $data = array(user => $user->toArray());
    return new JsonResponse($data);

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

by drak at 2012-02-16T11:51:11Z

@fabpot - maybe we could benefit with a bit more sub-namespacing in this component.  One for Response for example and probably one for Request.

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

by Seldaek at 2012-02-16T15:07:31Z

@drak Please no. Moving the session was already a pain IMO since it was type-hinted in a few places (lack of interface, and interface doesn't include flash stuff still). Creating BC breaks just for fun like that is annoying for interop of bundles. It doesn't matter whether we have 10 or 15 classes in one directory.

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

by drak at 2012-02-17T08:33:46Z

@francodacosta The most optimal place is `__toString()`.

@Saldaek It just looks like the whole namespace is getting more cluttered.  I suggest it because things like Request/Response objects are surely only going to grow over time.  There is always the possibility to make BC for moved and renamed classes so there doesn't have to be any extra complications for making things look cleaner. Anyway, just a thought :-)

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

by stof at 2012-02-17T14:47:40Z

@drak Changing the namespace of a class is a BC break. The request and the response are used in many more places than the Session so it would be a real pain to update this. And the component is tagged with ``@api`` so BC breaks are forbidden without a good reason. The session refactoring was one as it was really an issue in the implementation, but simply renaming the class is not.

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

by fabpot at 2012-03-05T15:03:53Z

I'm -1 for adding this to the core. It does not add much value and why add a special response for JSON and not other formats?

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

by Seldaek at 2012-03-05T18:38:05Z

I think it's useful because it's a class we need in almost every project, and I don't think we're alone. It's super simple but makes me wonder every time why I have to recreate it. I don't want an additional bundle just for 3lines of code. Similarly I would say a JsonpResponse would be great, or maybe just an optional $callback arg to the json response to enable jsonp mode.

I just had someone ask me on irc how to do JSONP so while I think it's obvious and I'm sure you'd think that too, it obviously isn't to newcomers. The Response stuff is hidden behind those render methods & such and people don't realize they can simply subclass. If a few examples were in core it would be both helpful for learning and useful on a day to day basis.

As for other formats, well JSON is typically used nowadays, except when you want more fancy XML APIs, but for that the JMSSerializerBundle + FOSRestBundle are superior and we can't achieve such things in a few lines of code. I could also see a BinaryResponse or DownloadResponse or such that has proper "force-download" headers and accepts any binary stream, but that's another debate.

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

by dragoonis at 2012-03-05T19:43:05Z

I'm +1 for the concept but not commenting on how it should be implemented I'll leave that to other people.

Typically when you want to force a download you have to do ``content-disposition: attachment; filename="filehere.pdf"``
Modifying some response headers and the likes automatically for the user by returning a DownloadResponse object would be very handy..

I'm +1 for @Seldaek's point about examples of sub-classing for specific use cases. It will help with demonstrating how to do custom stuff the right way rather than people coming up with their own contraptions.

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

by stof at 2012-03-05T20:14:39Z

btw, regarding the BinaryResponse, there is a pending PR about it: #2606

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

by simensen at 2012-03-05T21:07:33Z

I'm +1 for providing reference implementations fo custom Response cases. I wanted to find best practices for handling JSONP requests/responses and couldn't find anything at all on the topic. I thought maybe extending Response might be useful but wasn't sure if that could be done safely or should be done at all.

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

by lsmith77 at 2012-03-05T22:28:01Z

@stof i think @drak was suggesting moving the class, but leaving an empty class extending from the new class in the old location to maintain BC

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

by stof at 2012-03-05T23:55:36Z

@lsmith77 This would force Symfony to use the BC class so that it does not break all typehints in existing code

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

by lsmith77 at 2012-03-06T00:22:15Z

BC hacks are never nice .. the goal would just be to eventually have all those classes and more importantly all new ones in a subnamespace. actually it might be easier to just leave all the classes in the old location and create new ones extending from the old ones. anyway .. personally i am also not such a big fan of these specialized responses .. but i guess i see FOSRestBundle as the alternative answer which makes me biased.

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

by Seldaek at 2012-03-06T07:57:36Z

I'm using FOSRestBundle when it's needed, but when you just have a small scale app that needs one or two json responses for specialized stuff it is slightly overkill. And again, newcomers probably won't know about it, and encouraging using it for simple use cases isn't exactly the best learning curve we can provide.

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

by COil at 2012-03-06T23:12:15Z

+1 for this. I have implemented such a function in all my sf1 projects, it will be the same for sf2.

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

by fabpot at 2012-03-15T13:22:27Z

Closing this PR in favor of a cookbook that explains how a developer can override the default Response class (this JSON class being a good example). see symfony/symfony-docs#1159

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

by Seldaek at 2012-03-15T13:25:08Z

Meh. Forcing people to copy paste code from the cookbook in every second project isn't exactly a step forward with regard to ease of use and user-friendliness.

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

by Seldaek at 2012-03-15T13:26:48Z

I mean following this logic, things like the X509 authentication should just be put in cookbooks too because almost nobody needs that. We have tons of code in the framework, I don't get the resistance with adding such a simple class which makes code more expressive.

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

by fabpot at 2012-03-15T13:53:07Z

because X509 authentication is not easy to get it right. Sending a JSON response is as simple as it can get:

    new Response(json_encode($data), 200, array('Content-Type' => 'application/json'));

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

by marijn at 2012-03-15T13:54:25Z

Perhaps we need a `Symfony\Extensions\{Component}` namespace for things that don't necessarily belong in the core but are truly useful...

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

by Seldaek at 2012-03-15T14:03:40Z

I still fail to see why it doesn't belong in core.. There are tons of little helpers here and there, a base controller class made only of proxies, and then this gets turned down because it is simple to do it yourself? Sure it is simple, but it's repetitive and boring too. And while it's simple when you know your way around, some people aren't really sure how to do it.

The whole point of a framework is to avoid repetitive bullshit and be more productive. @fabpot do you have any real arguments against? I can see that you don't see a big use to it, fair enough, but do you see any downside at all?
2012-03-15 15:42:36 +01:00
Xavier Briand
1b395f5351 Revert "Throw exception when "date_widget" option is not equal to "time_widget""
This reverts commit 3c2539fccb.

Conflicts:

	tests/Symfony/Tests/Component/Form/Extension/Core/Type/DateTimeTypeTest.php
2012-03-15 15:32:52 +01:00
Drak
910b5c7f83 [HttpFoudation] CS, more tests and some optimization. 2012-03-15 12:15:54 +05:45
Drak
84c2e3caf7 [HttpFoundation] Allow flash messages to have multiple messages per type. 2012-03-15 11:55:52 +05:45
Drak
9a5fc659d7 [HttpFoundation] Add more tests. 2012-03-14 21:28:16 +05:45
Drak
7f33b33aa6 Refactor SessionStorage to NativeSessionStorage.
Native here refers to the fact the session storage interacts with real PHP sessions.
2012-03-14 20:59:57 +05:45
Drak
b12ece0ff7 [HttpFoundation][FrameworkBundle] Separate out mock session storage and stop polluting global namespace.
This makes mock sessions truly mock and not to interfere with global namespace.
Add getters and setters for session name and ID.
2012-03-14 20:32:06 +05:45
Drak
d687801142 [HttpKernel] Mock must invoke constructor. 2012-03-14 20:31:59 +05:45
Drak
7b36d0cc2b [DoctrineBridge][HttpFoundation] Refactored tests. 2012-03-14 20:30:06 +05:45
Drak
cb873b250b [HttpFoundation] Add tests and some CS/docblocks. 2012-03-14 20:29:58 +05:45
Drak
130831248d [HttpFoundation] Add and relocate tests. 2012-03-14 20:16:03 +05:45
Drak
88b1170356 [HttpFoundation] Refactor tests. 2012-03-14 20:15:59 +05:45