Skip to content

[FrameworkBundle] Added configuration for additionnal request formats #8944

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
Closed

Conversation

gquemener
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? no
Fixed tickets #8934
License MIT
Doc PR ~

TODO

  • Fix wrong xml configuration definition
  • Write documentation (new entry or replace symfony.com/doc/current/cookbook/request/mime_type.html ?)

->info('request configuration')
->canBeUnset()
->children()
->arrayNode('additionnal_formats')
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes indeed... Sorry

@hacfi
Copy link
Contributor

hacfi commented Sep 6, 2013

+1

AsseticBundle currently has a RequestListener which just adds additional formats. It makes sense to let bundles use this feature too. So how about adding a service tag?

@stof
Copy link
Member

stof commented Sep 6, 2013

@hacfi Additional formats are not services. So using a tag would require creating hacky services.

Such bundles should prepend configurations if they want to add some formats

->arrayNode('request')
->info('request configuration')
->canBeUnset()
->children()
Copy link
Member

Choose a reason for hiding this comment

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

You are missing the ->fixXmlConfig('additional_format') call to make the prototyped node work properly for XML configs

@stof
Copy link
Member

stof commented Sep 6, 2013

the XSD must be updated as well

@hacfi
Copy link
Contributor

hacfi commented Sep 6, 2013

@stof Good to know - thanks!

@gquemener
Copy link
Contributor Author

I'm wondering, does it worth it to add a setFormats method inside the listener in order to allow injecting the formats manually?

@hacfi
Copy link
Contributor

hacfi commented Sep 6, 2013

@gquemener What do you mean by injecting formats manually?

As the listener will only use onKernelRequest I suggest to use an event listener instead of a subscriber. What do you think?

@gquemener
Copy link
Contributor Author

@hacfi I was thinking of injecting the formats from a controller, but it doesn't make any sense. Let's forget the idea!

@gquemener
Copy link
Contributor Author

@gquemener
Copy link
Contributor Author

@stof I've updated the xsd to allow using the following structure:

  <request>
    <additional-format name="csv">
      <mime-type>text/csv</mime-type>
    </additional-format>
  </request>

What do you think about it and does the Configuration class needs some changes, please?

@stof
Copy link
Member

stof commented Sep 6, 2013

@gquemener The XML would not look like this but will be

<request>
    <additional-format name="csv">text/csv</additional-format>
    <additional-format name="gif">imgae/gif</additional-format>
  </request>

as it is a scalar prototype

->fixXmlConfig('additional-format')
->children()
->arrayNode('additional_formats')
->prototype('array')
Copy link
Member

Choose a reason for hiding this comment

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

you are still missing the call to useAttributeAsKey. Please add a test using this feature in different formats to see that it is broken currently

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok thanks, will do soon

@gquemener gquemener closed this Sep 6, 2013
@gquemener gquemener reopened this Sep 6, 2013
@lsmith77
Copy link
Contributor

lsmith77 commented Sep 7, 2013

Btw FOSRestBundle also already provides this

<xsd:choice minOccurs="1" maxOccurs="unbounded">
<xsd:element name="mime-type" type="xsd:string" />
</xsd:choice>
<xsd:attribute name="name" type="xsd:string" />
Copy link
Member

Choose a reason for hiding this comment

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

you should mark this attribute as required as we use it as key

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok thanks I'll fix it.

I'm still having issue finding the correct way to support https://github.com/symfony/symfony/pull/8944/files#L11R131 using xml.

@docteurklein rose up the fact that it might not be possible (gquemener@b41388e#commitcomment-4065417), but the FrameworkExtensionTest architecture suggest that all configuration format should behave identically. Is it okay if it's not the case?

I mean, is it ok if it's not possible to define multiple mime-types for a given format when using xml?

@jakzal
Copy link
Contributor

jakzal commented Dec 22, 2013

@gquemener are you still interested in finishing this one off? Does it still make sense if FOSRestBundle already provides this feature and we've got a cookbook on how to do it with a request listener?

{
$this->assertEquals(array(
KernelEvents::REQUEST => 'onKernelRequest',
), AddRequestFormatsListener::getSubscribedEvents());
Copy link
Contributor

Choose a reason for hiding this comment

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

is this indentation correct?

@gquemener
Copy link
Contributor Author

@jakzal Yes I'm still interested but I was struggling with the xml configuration definition, and didn't have time to find the correct solution.

I think it'd be interesting to have this configuration directly into Symfony (as you might want to use it without using FOSRestBundle, as you don't want any rest api). Anyway, As I say, I'm hardly struggling with the xml definition, so I'm gonna take a look at how FOSRestBundle did it.

@cordoval
Copy link
Contributor

is it the schema thing @gquemener ? or other part of configurations? just curious

@gquemener
Copy link
Contributor Author

Yes it's the xml schema. AFAIR, I had trouble defining the additionnal formats the same way in yaml and in xml.

@cordoval
Copy link
Contributor

something that may help is a library i saw the other day it would turn yml -> xml schema i think, but i may be wrong, let me check the lib and come back to you, maybe it can help but if not then so be it. 👶

@cordoval
Copy link
Contributor

@gquemener romaricdrigon/MetaYaml#6 this was what i was talking about, not sure how useful

@wouterj
Copy link
Member

wouterj commented Dec 24, 2013

To support your current XSD/XML, you need to add a normalizer (and I think that's perfectly valid to do):

->beforeNormalization()
    ->ifTrue(function ($v) { return is_array($v) && isset($v['mine_type']) })
    ->then(function ($v) { return $v['mine_type'] }
->end()

@gquemener
Copy link
Contributor Author

Good to know @wouterj, I'll try asap! thanks 🎄

Conflicts:
	src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
@gquemener
Copy link
Contributor Author

I'm closing this PR and reopening a new one, as the diff has became too huge in 3 months!

@gquemener gquemener closed this Dec 25, 2013
@gquemener
Copy link
Contributor Author

PR is coming as soon as my "backend storage" is online
capture du 2013-12-25 22 41 01

fabpot added a commit that referenced this pull request Feb 20, 2014
…equest formats (gquemener)

This PR was squashed before being merged into the 2.5-dev branch (closes #9862).

Discussion
----------

[FrameworkBundle] Added configuration for additionnal request formats

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #8934
| License       | MIT
| Doc PR        |  symfony/symfony-docs#3402

Reopening of #8944

# TODO
  - [x] Fix wrong xml configuration definition (Thanks @wouterj)
  - [x] Change configuration key `additional_formats` to a more meaningful one
  - [x] Write documentation (new entry or replace http://symfony.com/doc/current/cookbook/request/mime_type.html ?)

Commits
-------

f90ba11 [FrameworkBundle] Added configuration for additionnal request formats
fabpot added a commit to symfony/framework-bundle that referenced this pull request Feb 20, 2014
…equest formats (gquemener)

This PR was squashed before being merged into the 2.5-dev branch (closes #9862).

Discussion
----------

[FrameworkBundle] Added configuration for additionnal request formats

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | symfony/symfony#8934
| License       | MIT
| Doc PR        |  symfony/symfony-docs#3402

Reopening of symfony/symfony#8944

# TODO
  - [x] Fix wrong xml configuration definition (Thanks @wouterj)
  - [x] Change configuration key `additional_formats` to a more meaningful one
  - [x] Write documentation (new entry or replace http://symfony.com/doc/current/cookbook/request/mime_type.html ?)

Commits
-------

f90ba11 [FrameworkBundle] Added configuration for additionnal request formats
fabpot added a commit to symfony/http-kernel that referenced this pull request Feb 20, 2014
…equest formats (gquemener)

This PR was squashed before being merged into the 2.5-dev branch (closes #9862).

Discussion
----------

[FrameworkBundle] Added configuration for additionnal request formats

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | symfony/symfony#8934
| License       | MIT
| Doc PR        |  symfony/symfony-docs#3402

Reopening of symfony/symfony#8944

# TODO
  - [x] Fix wrong xml configuration definition (Thanks @wouterj)
  - [x] Change configuration key `additional_formats` to a more meaningful one
  - [x] Write documentation (new entry or replace http://symfony.com/doc/current/cookbook/request/mime_type.html ?)

Commits
-------

f90ba11 [FrameworkBundle] Added configuration for additionnal request formats
fabpot added a commit to symfony/framework-bundle that referenced this pull request Nov 11, 2014
…equest formats (gquemener)

This PR was squashed before being merged into the 2.5-dev branch (closes #9862).

Discussion
----------

[FrameworkBundle] Added configuration for additionnal request formats

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | symfony/symfony#8934
| License       | MIT
| Doc PR        |  symfony/symfony-docs#3402

Reopening of symfony/symfony#8944

# TODO
  - [x] Fix wrong xml configuration definition (Thanks @wouterj)
  - [x] Change configuration key `additional_formats` to a more meaningful one
  - [x] Write documentation (new entry or replace http://symfony.com/doc/current/cookbook/request/mime_type.html ?)

Commits
-------

f90ba11 [FrameworkBundle] Added configuration for additionnal request formats
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants