-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
[Asset] added the component #13234
[Asset] added the component #13234
Conversation
e716f76
to
c9e9565
Compare
10c720c
to
95f7b7f
Compare
->canBeUnset() | ||
->fixXmlConfig('base_url') | ||
->children() | ||
->scalarNode('version')->defaultValue(null)->end() |
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.
wouldn't it be better defaultNull
?
I like the overall simplification, no more weird behaviour depending on wether your packages contain ssl/non-ssl urls. |
"php": ">=5.3.3" | ||
}, | ||
"suggest": { | ||
"symfony/http-foundation": "" |
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.
👍 thanks for this "totaly" standalone component !
6439559
to
b0bc46f
Compare
@@ -442,6 +444,54 @@ private function addTemplatingSection(ArrayNodeDefinition $rootNode) | |||
; | |||
} | |||
|
|||
private function addAssetsSection(ArrayNodeDefinition $rootNode) | |||
{ |
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 code reminds me http://www.history.com/topics/ancient-history/the-egyptian-pyramids, 👯 #troll
{ | ||
// BC layer to be removed in 3.0 | ||
if (2 < $count = func_num_args()) { | ||
trigger_error('Generating absolute URL with the Twig asset() function was deprecated in 2.7 and will be removed in 3.0. Please use absolute_url() instead.', E_USER_DEPRECATED); |
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.
"Generating an absolute URL [...]" or "Generating absolute URLs [...]"?
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.
fixed
4283428
to
48d3d15
Compare
} | ||
|
||
/** | ||
* @return ContextInterface|null |
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 cannot be null
anymore
48d3d15
to
c8b799c
Compare
c8b799c
to
0750d02
Compare
This PR was merged into the 2.7 branch. Discussion ---------- [Asset] added the component | Q | A | ------------- | --- | Bug fix? | yes | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | #10973, #11748, #11876, #4883, #12474 | License | MIT | Doc PR | not yet TODO: - [ ] submit documentation PR The current Asset sub-namespace in Templating has several (major) problems: * It does not cover all use cases (see #10973 and #4883 for some example) * It has some design issues (relies on the Request instance and so requires the request scope, very coupled with the PHP templating sub-system, see #11748 and #11876) To decouple this feature and make it reusable in Silex for instance, and to fix the design issues and make it more extensible, I've decided to extract and rework the features provided into a new Asset component. Basically, this component allows the developer to easily manage asset URLs: versioning, paths, and hosts. Both the new and the old asset management features are kept in this PR to avoid breaking BC; the old system is of course deprecated and automatically converted to the new one. Even if the features are quite similar, and besides the flexilibity of the new system, here are some differences: * `PathPackage` always prepend the path (even if the given path starts with `/`). * Usage is stricter (for instance, `PathPackage` requires a basePath to be passed and `UrlPackage` requires that at least on URL is passed). * In the configuration, named packages inherits from the version and version format of the default package by default. * It is not possible to override the version when asking for a URL (instead, you can define your own version strategy implementation -- the use cases explained in #6092 are easily implemented this way). * It's not possible to generate absolute URLs (see #13264 for a better alternative using composition; so using `absolute_url(asset_path('me.png')) should work)`. #10973 was about adding shortcuts for bundles, which is a good idea; but given that you rarely reference built-in or third-party bundle assets and because we now have a one-bundle default approach named AppBundle, the same can be achieved with just a simple piece of configuration with the new assets feature: ```yml framework: assets: packages: app: base_path: /bundles/app/ img: base_path: /bundles/app/images/ ``` Then: ```jinja {{ asset('images/me.png', 'app') }} # /bundles/app/images/me.png {{ asset('me.png', 'img') }} # /bundles/app/images/me.png ``` #12474 discussed the possibility to add a version for absolute URL. It's not possible to do that in a generic way as the version strategy involves both the version and the path, which obviously cannot work when the path is an absolute URL already. Instead, one should use the `asset_version` Twig function to add the version manually. Commits ------- 0750d02 removed usage of the deprecated forms of asset() in the core framework f74a1f2 renamed asset_path() to asset() and added a BC layer 4d0adea [Asset] added a NullContext class d33c41d [Asset] added the component
The following does not work anymore: img src="{{ asset('images/user.png', 'images') | imagine_filter('default') }}" alt="Image de profil" class="img-circle whitebg" |
@svassaux if you think there's a bug, please create a new issue. |
If use absolute_url() for image from the CLI the url is without host, because masterRequest is empty. |
@12th there's a cookbook on that! http://symfony.com/doc/current/cookbook/console/sending_emails.html |
@acasademont
Services
Config:
When try use flush the queue after send, catch error User Error: Call to undefined method getSpool
If dump getMasterRequest() in generateAbsoluteUrl(), the request is null, and I get path without host
|
that's why you have the asset_base_url :p http://symfony.com/doc/current/reference/configuration/framework.html#assets-base-urls |
And whether it is possible to dynamically change depending on the sender's e-mail settings? |
mmm you would need to create a "package" for each of them and have different url's in there http://symfony.com/doc/current/reference/configuration/framework.html#packages |
Alternatively I try, but it's not the best option because the sender to the individual letters is different and is selected from the panel |
If set host in package base_path
template lokk like:
the html look like
with slash at the beginning of the address |
as a solution to use
|
Solution there #15448 |
TODO:
The current Asset sub-namespace in Templating has several (major) problems:
To decouple this feature and make it reusable in Silex for instance, and to fix the design issues and make it more extensible, I've decided to extract and rework the features provided into a new Asset component.
Basically, this component allows the developer to easily manage asset URLs: versioning, paths, and hosts.
Both the new and the old asset management features are kept in this PR to avoid breaking BC; the old system is of course deprecated and automatically converted to the new one.
Even if the features are quite similar, and besides the flexilibity of the new system, here are some differences:
PathPackage
always prepend the path (even if the given path starts with/
).PathPackage
requires a basePath to be passed andUrlPackage
requires that at least on URL is passed).absolute_url(asset_path('me.png')) should work)
.[assets] bundle package #10973 was about adding shortcuts for bundles, which is a good idea; but given that you rarely reference built-in or third-party bundle assets and because we now have a one-bundle default approach named AppBundle, the same can be achieved with just a simple piece of configuration with the new assets feature:
Then:
#12474 discussed the possibility to add a version for absolute URL. It's not possible to do that in a generic way as the version strategy involves both the version and the path, which obviously cannot work when the path is an absolute URL already. Instead, one should use the
asset_version
Twig function to add the version manually.