Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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

Closed
ro0NL wants to merge3 commits intosymfony:3.4fromro0NL:asset/router-context
Closed

[Asset] Provide default context#21027

ro0NL wants to merge3 commits intosymfony:3.4fromro0NL:asset/router-context

Conversation

@ro0NL
Copy link
Contributor

@ro0NLro0NL commentedDec 22, 2016
edited
Loading

QA
Branch?3.4
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#19396
LicenseMIT
Doc PRshould be noted somewhere, ill create an issue

Allows configuring the default asset context to make things works on CLI for example. Same approach as the routing component.

Introduces

# parameters.ymlasset.request_context.base_path:'/base/path'asset.request_context.secure:false

Koc and MrMitch reacted with thumbs up emoji
<argumenttype="collection" /><!-- named packages-->
</service>

<serviceid="assets.empty_package"class="Symfony\Component\Asset\Package"public="false">
Copy link
Member

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

Copy link
ContributorAuthor

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>
Copy link
Member

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)

Copy link
ContributorAuthor

@ro0NLro0NLDec 22, 2016
edited
Loading

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()) {
Copy link
Member

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)

Copy link
ContributorAuthor

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;
Copy link
Member

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

ro0NL reacted with thumbs up emoji
* @param int $httpsPort The HTTPS port
* @param string $path The path
* @param string $queryString The query string
* @param string $basePath The base path
Copy link
Member

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

Copy link
ContributorAuthor

@ro0NLro0NLDec 22, 2016
edited
Loading

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
Copy link
ContributorAuthor

ro0NL commentedDec 22, 2016
edited
Loading

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.

jvasseur and MrMitch reacted with thumbs up emoji

@ro0NL
Copy link
ContributorAuthor

ro0NL commentedDec 22, 2016
edited
Loading

There are 2 viable options to me;

  • this approach
  • introduce a new%asset.default_base_path% param and provide a default context

Option 2 is also reasonable, and may perhaps be the better approach. However i chose this one as we already introduced routing params, and it will work for people who already set the base url with it (not sure about that actually).

edit:
After all, I think we should go with

assets:context:base_path:'%asset.context.base_path%'secure:'%asset.context.secure%'# ...

Any thoughts?

edit: yep, basically#19396 (comment) 😅

@ro0NLro0NL changed the title[Asset][Routing] Bridge asset with request context from routing[Asset] Provide default contextDec 24, 2016
@ro0NL
Copy link
ContributorAuthor

@stof different approach, way simpler :) WDYT?

@nicolas-grekas
Copy link
Member

Since this adds new parameters, this is not a bug but only a feature.
Doc PR should be opened before merging, because that's the only way to know about the params.
About the params, they are obscure things usually to users, which means very little are going to know about them and their purpose, even if it's documented.
Which means we shouls try hard tonot add new params when possible (I don't know here, just emphasizing this important point :) .)

@nicolas-grekasnicolas-grekas added this to the3.x milestoneDec 27, 2016
@ro0NL
Copy link
ContributorAuthor

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
Copy link
Member

Before the introduction of the new Asset component theasset() function made use of the request context config options, right?

@ro0NL
Copy link
ContributorAuthor

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.

/request-base/app_dev.php/route/request-base/asset-base/asset vs. /request-base/app_dev.php/asset-base/asset

@ro0NL
Copy link
ContributorAuthor

ro0NL commentedDec 29, 2016
edited
Loading

I guess practically one could get away with configuring package base urls, going absolute. BypassingRequestStackContext::getBasePath and no support for relative URL's :)

@xabbuh
Copy link
Member

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
Copy link
ContributorAuthor

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.

Im not sure i follow.. i did a quik test; installed latest 2.7 in a subdir (reachable athttp://symfony-sub.dev/sf27/web/app_dev.php)

Updated framework config withassets: { version: 1, base_path: /assets }

Updatedapp/Resources/views/default/index.html.twig to display{{ asset('foo.jpg') }}

Added a commandtest with$output->writeln($this->getContainer()->get('twig')->render(':default:index.html.twig'));

Results :)

image

image

What did we removed? Or what am i missing here?

@xabbuh
Copy link
Member

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
Copy link
ContributorAuthor

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
Copy link
ContributorAuthor

ro0NL commentedDec 29, 2016
edited
Loading

Oh, and it's totally fixable in user land. So we can always keep things as is here; an unsupported feature.

@xabbuh
Copy link
Member

Oh, and it's totally fixable in user land. So we can always keep things as is here; an unsupported feature.

But the thing is that this used to work before (theasset() function did exist before the introduction of the Asset component in#13234, seehttps://github.com/symfony/symfony/blob/2.3/src/Symfony/Bundle/TwigBundle/Extension/AssetsExtension.php#L55).

@ro0NL
Copy link
ContributorAuthor

ro0NL commentedDec 29, 2016
edited
Loading

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.

@ro0NLro0NL closed thisDec 29, 2016
@ro0NLro0NL reopened thisDec 29, 2016
@ro0NL
Copy link
ContributorAuthor

ro0NL commentedDec 29, 2016
edited
Loading

Now we could do it convention wise perhaps, making use of%router.request_context.base_url%.

If ending with/ it's the base path (/request-base/), otherwise it's the base URL (/request-base/app_dev.php) and we do adirname. Could work...

@xabbuh
Copy link
Member

@ro0NL I'll look into an old 2.3 application to check how exactly it used to work then.

@ro0NL
Copy link
ContributorAuthor

ro0NL commentedJul 12, 2017
edited
Loading

@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).

About the params, they are obscure things usually to users, which means very little are going to know about them and their purpose, even if it's documented.

I tend to believe people will bump into it (if documented somewhere of course) once dealing with this issue =/

@nicolas-grekas
Copy link
Member

can you add a changelog line to advertise the feature?
also, should we add corresponding config options? not sure, just wondering.

@ro0NLro0NL changed the base branch frommaster to3.4September 2, 2017 07:24
@ro0NL
Copy link
ContributorAuthor

Changelog added; extra config is not needed IMHO; it's the same approach as routing does.

Because of that ive renamed the params to%asset.request_context.*% so it's in line with%router.request_context.*%

* 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
Copy link
Member

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

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
Copy link
ContributorAuthor

changelog updated. Not sure about a note in assets component; change is in no way related to that.

@nicolas-grekas
Copy link
Member

ping@fabpot as I guess you're the one merging on Asset?

@ro0NL
Copy link
ContributorAuthor

ro0NL commentedSep 18, 2017
edited
Loading

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
Copy link
Member

Thank you@ro0NL.

fabpot added a commit that referenced this pull requestSep 28, 2017
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
@fabpotfabpot closed thisSep 28, 2017
@ro0NLro0NL deleted the asset/router-context branchOctober 5, 2017 11:11
This was referencedOct 18, 2017
fabpot added a commit that referenced this pull requestMay 5, 2020
…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
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@stofstofstof left review comments

@xabbuhxabbuhxabbuh approved these changes

@fabpotfabpotfabpot approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

3.4

Development

Successfully merging this pull request may close these issues.

6 participants

@ro0NL@nicolas-grekas@xabbuh@fabpot@stof@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp