pamiris/javascript-constants
最新稳定版本:0.1.1
Composer 安装命令:
composer require pamiris/javascript-constants
包简介
A simple tool for converting PHP constant classes into javascript constant objects
README 文档
README
A simple tool for porting PHP constant classes to javascript constant objects
Installation
As a dependency
Run composer require pamiris/javascript-constants
-- or --
Add the following line to your composer.json:
{
"require": {
"pamiris/javascript-constants": "*"
}
}
Usage
To get the executable javascript to define the object, pass the classname and an optional target name into the tool; then include the resulting js inside a script tag on your template:
<?php //src/myprocject/controller.php ... use Pamiris\JavascriptConstants\Mapper as ConstantMapper; ... function someAction() { $jsConstants = ConstantMapper::getJavascriptObject('MyNamespace\MyClass'); $this->renderTemplate('mypage',[ ... 'scriptContent' => $jsConstants ]);
{# /myproject/page.html.twig #} {% extends base.html.twig %} {% block javascripts %} <script>{{ scriptContent | raw }}</script> {% endblock %}
TODO
Add Twig extension and bundle to auto-configure.
Notes
This requires ES2015, which is supported in most broswers. Safari will let you overwrite the objects, Chrome and Firefox will not.
License
PHP JavascriptConstants is licensed under the MIT License - see the LICENSE file for details.
统计信息
- 总下载量: 333
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-05-31