Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Asset] Provide default context#21027
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
| <argumenttype="collection" /><!-- named packages--> | ||
| </service> | ||
| <serviceid="assets.empty_package"class="Symfony\Component\Asset\Package"public="false"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
removing this service is a BC break, as people might reference it in their config. Please keep it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Can we deprecate it?
| <parameterkey="router.request_context.host">localhost</parameter> | ||
| <parameterkey="router.request_context.scheme">http</parameter> | ||
| <parameterkey="router.request_context.base_url"></parameter> | ||
| <parameterkey="router.request_context.base_path">%router.request_context.base_url%</parameter> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
this default is weird, as the base path is a subpart of the base url (the base url may have/app_dev.php in it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Agree..base_url should default tobase_path right?
| */ | ||
| publicfunctioncreateContext() | ||
| { | ||
| if (null !==$this->requestStack &&$this->requestStack->getMasterRequest()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
this is wrong, as the request may be injected in the request stack later than that. You cannot instantiate the service based on the availability of the Request, as it would change the behavior depending on when the context is instantiated (which depends on what needs it in the container and so is unknown to you)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Correct. What about a directPHP_SAPI check?
| */ | ||
| publicfunctionisSecure() | ||
| { | ||
| return$this->secure; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
should be detected based on the RequestContext scheme instead
| * @param int $httpsPort The HTTPS port | ||
| * @param string $path The path | ||
| * @param string $queryString The query string | ||
| * @param string $basePath The base path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
this looks weird to me, because the Routing component never needs the base path
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
True, however for being arequest context it seemed a reasonable feature to me. And more important, allows this fix :))
edit: we cannot simply rely ondirname($baseUrl) i guess..
ro0NL commentedDec 22, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Imo. the behavior is buggy, and this is my approach to revise it (i may do PR's right?). I explained why imo. it's needed, so feel free to argue. |
ro0NL commentedDec 22, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There are 2 viable options to me;
Option 2 is also reasonable, and may perhaps be the better approach. However i chose this one as we already introduced routing params edit: assets:context:base_path:'%asset.context.base_path%'secure:'%asset.context.secure%'# ... Any thoughts? edit: yep, basically#19396 (comment) 😅 |
ro0NL commentedDec 24, 2016
@stof different approach, way simpler :) WDYT? |
nicolas-grekas commentedDec 27, 2016
Since this adds new parameters, this is not a bug but only a feature. |
ro0NL commentedDec 27, 2016
Agree.. on the params. Im not even sure we need them, same for routing context params actually; see#21043 However the bug is real. |
xabbuh commentedDec 28, 2016
Before the introduction of the new Asset component the |
ro0NL commentedDec 29, 2016
Not sure, i should have a look at that. Fact is (given the current context options) we cannot go from base url to base path genericly. |
ro0NL commentedDec 29, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I guess practically one could get away with configuring package base urls, going absolute. Bypassing |
xabbuh commentedDec 29, 2016
As this used to work in previous releases we should at least strive to make the Asset component compatible with how the Twig functions used to work before. We can still think about how to make things better and deprecate stuff in 3.3/3.4. |
ro0NL commentedDec 29, 2016
Im not sure i follow.. i did a quik test; installed latest 2.7 in a subdir (reachable at Updated framework config with Updated Added a command Results :)What did we removed? Or what am i missing here? |
xabbuh commentedDec 29, 2016
I mean before the introduction of the Asset component (so you will have to use a Symfony version before 2.7 to see how it used to behave back then). |
ro0NL commentedDec 29, 2016
I see. Not gonna investigate that now :) I mean, i cannot really compare the asset component against nothing. Either the approach was the same-ish, or it suffered from the same problem. Here's my approach for 2.7 and up 👍 (perhaps along with#21043). But again, if im missing something in terms of a different approach done previously.. let me know :) |
ro0NL commentedDec 29, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Oh, and it's totally fixable in user land. So we can always keep things as is here; an unsupported feature. |
xabbuh commentedDec 29, 2016
But the thing is that this used to work before (the |
ro0NL commentedDec 29, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I think looking athttps://github.com/symfony/symfony/blob/2.3/src/Symfony/Bundle/FrameworkBundle/Templating/Asset/PathPackage.php#L31 andhttps://github.com/symfony/symfony/blob/2.3/src/Symfony/Component/Templating/Asset/PathPackage.php#L35 it suffered the same problem. But im really not aware of any CLI defaulting with params or so in 2.3, which would be basically this approach. |
ro0NL commentedDec 29, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Now we could do it convention wise perhaps, making use of If ending with |
xabbuh commentedDec 29, 2016
@ro0NL I'll look into an old 2.3 application to check how exactly it used to work then. |
ro0NL commentedJul 12, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@xabbuh any news? :P Prettiest fix is still#21043 IMO. But this PR should do as well :-) Otherwise im planning to close; as it's solvable in userland by using a package base URL (coming from a custom param or so).
I tend to believe people will bump into it (if documented somewhere of course) once dealing with this issue =/ |
nicolas-grekas commentedAug 31, 2017
can you add a changelog line to advertise the feature? |
ro0NL commentedSep 2, 2017
Changelog added; extra config is not needed IMHO; it's the same approach as routing does. Because of that ive renamed the params to |
| * Deprecated`Symfony\Bundle\FrameworkBundle\Translation\TranslationLoader`, use | ||
| `Symfony\Component\Translation\Reader\TranslationReader` instead | ||
| * Deprecated`translation.loader` service, use`translation.reader` instead | ||
| * Added`asset.request_context.base_path` and`asset.request_context.secure` parameters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
we could add an entry to the changelog file of the Asset component too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
and hint a bit more why they're useful :)
ro0NL commentedSep 6, 2017
changelog updated. Not sure about a note in assets component; change is in no way related to that. |
nicolas-grekas commentedSep 18, 2017
ping@fabpot as I guess you're the one merging on Asset? |
ro0NL commentedSep 18, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Also im not experiencing this issue myself. Honestly thought to fixlinked issue real quick :) confirmed as it is (#19396 (comment)). Not sure what's blocking here. However i dont wanna imply im pushing this PR or so. edit: as this is a new feature; now polished :) |
fabpot commentedSep 28, 2017
Thank you@ro0NL. |
This PR was squashed before being merged into the 3.4 branch (closes#21027).Discussion----------[Asset] Provide default context| Q | A| ------------- | ---| Branch? | 3.4| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#19396| License | MIT| Doc PR | should be noted somewhere, ill create an issueAllows configuring the default asset context to make things works on CLI for example. Same approach as the routing component.Introduces```yaml# parameters.ymlasset.request_context.base_path: '/base/path'asset.request_context.secure: false```Commits-------9137d57 [Asset] Provide default context
…r assets (nicolas-grekas)This PR was merged into the 5.1-dev branch.Discussion----------[FrameworkBundle] use the router context by default for assets| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| Deprecations? | no| Tickets | -| License | MIT| Doc PR | -Follows#36651 and#21027This means assets are going to be configured automatically most of the time. The only case where `asset.request_context.base_path` is useful is when the webserver still keeps a `/index.php/` in URLs. (I'm not sure if the doc should tell ppl to use the parameter, or if we should tell ppl to improve the config of their server...)Commits-------1ac5f68 [FrameworkBundle] use the router context by default for assets


Uh oh!
There was an error while loading.Please reload this page.
Allows configuring the default asset context to make things works on CLI for example. Same approach as the routing component.
Introduces