creative-web-solution/front-polyfill-bundle
Composer 安装命令:
composer require creative-web-solution/front-polyfill-bundle
包简介
Generate the necessary polyfill.
README 文档
README
Configuration
Create a YAML file:
You can copy the Resources/sample/config.yaml in your app (in /frontend/polyfill/config.yaml for example).
You can configure this path by overriding this parameters in your app:
parameters:
cws.polyfill.config_path: /frontend/polyfill/config.yaml
Activate the polyfills you need by setting active: true in this config file.
Services
Add this line in the import section of your services.yaml
imports:
- { resource: '@CwsFrontPolyfillBundle/Resources/config/services.xml' }
Javascript support tests
Get the active polyfill list:
With an object list
{% set polyfillList = get_front_polyfill_list() %}
<script>
var myPolyfillArray = [
{%- for name, polyfill in polyfillList.list -%}
{
"test": {{ polyfill.test|raw }},
"name": "{{ name|raw }}"
}{{ loop.last ? '' : ',' }}
{%- endfor -%}
];
</script>
With a JS array-like string
var myPolyfillArray = {{ get_front_polyfill_list('js') }};
This will give :
var myPolyfillArray = [ { "test": test1, "name": "test1" },{ "test": test2, "name": "test2" }, ... ];
You can change the name of the properties:
var myPolyfillArray = {{ get_front_polyfill_list('js', 'a', 'b') }};
Results in :
var myPolyfillArray = [{ "b": test1, "a": "test1" },{ "b": test2, "a": "test2" }, ... ];
Here a full example to create an url like 'js/pf1-pf2-pf3.js':
{% set polyfillArrayString = get_front_polyfill_list('js') %}
<script>
let polyfillContentUrl;
{%- if polyfillArrayString is defined and polyfillArrayString|length > 2 -%}
let neededPolyfill = [];
{{ polyfillArrayString }}
.forEach( function( polyfill ) {
if (typeof polyfill.test === 'function' && polyfill.test() ||
typeof polyfill.test !== 'function' && polyfill.test) {
neededPolyfill.push( polyfill.name );
}
});
if ( neededPolyfill.length ) {
polyfillContentUrl = `js/${ neededPolyfill.join( '-' ) }.js`;
}
{%- endif -%}
[
polyfillContentUrl,
'1.js',
'2.js'
].forEach( function( src ) {
if ( !src ) {
return;
}
var script = document.createElement('script');
script.src = src;
script.async = false;
document.head.appendChild(script);
} );
</script>
Polyfill loading
Use the array of test to create an url to load the polyfill content.
There is 2 ways to load the polyfills:
1/ The polyfill names are contained in the filename itself and separated by -
This is the recommended way to do it because this way allow you to create a real file. Handy with Symfony as if the file exists, it will not be rerendered.
<script src="js/polyfill-domch-eachnl-picture.js"></script>
Inside the Twig file that render the response for polyfill-domch-eachnl-picture.js (and save the file if you want):
{{ get_front_polyfill_content()|raw }}
// Other stuff in JS
The route to this file MUST contains a placeholder. By default its name is polyfill_list. So, in our example /js/polyfill-domch-eachnl-picture.js, the route must be /js/polyfill-{polyfill_list}.js
You can configure the placeholder name in the parameters.yaml:
parameters:
cws.polyfill.route_placeholder: polyfill_list
When there is a clear cache action, it is recommended to delete those generated files as well.
2/ The polyfill names are contained in the query string and separated by &
<script src="js/polyfill.js?domch&eachnl&picture"></script>
Tou have to specify it using the parameter query of the get_front_polyfill_content TWIG function.
Inside the Twig file that render the response for polyfill.js:
{{ get_front_polyfill_content('query')|raw }}
// Other stuff in JS
creative-web-solution/front-polyfill-bundle 适用场景与选型建议
creative-web-solution/front-polyfill-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9.24k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 02 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「bundle」 「front」 「polyfill」 「symfony4」 「cws」 「creative-web-solution」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 creative-web-solution/front-polyfill-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 creative-web-solution/front-polyfill-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 creative-web-solution/front-polyfill-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A polyfill for pthreads
2lenet/EasyAdminPlusBundle
The bundle for easy using json-rpc api on your project
Provide a way to secure accesses to all routes of an symfony application.
Compatibility layer for emulating enumerations in PHP < 8.1 and native enumerations in PHP >= 8.1
PHP polyfill for the Apache Functions. The aim is to provides functions as the PHP way in order to get them available even if PHP is not running as an Apache module.
统计信息
- 总下载量: 9.24k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 25
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-02-05