endroid/qr-code-bundle
Composer 安装命令:
composer require endroid/qr-code-bundle
包简介
Endroid QR Code Bundle
README 文档
README
By endroid
This Symfony bundle lets you generate QR Codes using the endroid/qr-code library. It provides the following features:
- Configure your defaults (like image size, default writer etc.)
- Support for multiple configurations and injection via aliases
- Generate QR codes for defined configurations via URL like /qr-code//Hello
- Generate QR codes or URLs directly from Twig using dedicated functions
Installation
Use Composer to install the library. Also make sure you have enabled and configured the GD extension if you want to generate images.
composer require endroid/qr-code-bundle
Route Configuration
By default the bundle registers a controller that generates QR codes via the URL
/qr-code/{builder}/{data}. If you only use QR codes programmatically or via Twig
and don't need the route, you can disable it. You can also set a custom prefix.
endroid_qr_code: route_enabled: true route_prefix: '/my-custom-prefix'
This makes the route available at /my-custom-prefix/{builder}/{data}.
Builder Configuration
The bundle makes use of builders to create QR codes. The default parameters applied by the builder can optionally be overridden via the configuration. And multiple configurations (thus builders) can be defined.
Each entry under builders defines a named builder with its own defaults.
When no builders are configured the bundle registers a single default builder.
endroid_qr_code: builders: default: writer: Endroid\QrCode\Writer\PngWriter data: 'This is customized QR code' logo_path: '%kernel.project_dir%/vendor/endroid/qr-code/tests/assets/symfony.png' logo_resize_to_width: 150 logo_punchout_background: true # only supported by PngWriter label_text: 'This is the label' label_font_path: '%kernel.project_dir%/vendor/endroid/qr-code/assets/noto_sans.otf' label_font_size: 20 label_alignment: 'center' custom: writer: Endroid\QrCode\Writer\SvgWriter writer_options: exclude_xml_declaration: true # default: false data: 'This is customized QR code' size: 300 encoding: 'UTF-8' error_correction_level: 'low' # 'low', 'medium', 'quartile', or 'high' round_block_size_mode: 'margin' validate_result: false
Using Named Builders
Each builder is available for injection using its name suffixed with
QrCodeBuilder. For example the custom builder above can be injected as
$customQrCodeBuilder. You can override the configured defaults at build time:
use Endroid\QrCode\Builder\BuilderInterface; public function __construct(BuilderInterface $customQrCodeBuilder) { $result = $customQrCodeBuilder->build( size: 400, margin: 20 ); }
QR Code Response
The bundle also provides a response object to ease rendering of the resulting image by automatically saving to contents and setting the correct content type.
use Endroid\QrCodeBundle\Response\QrCodeResponse; $response = new QrCodeResponse($result);
Twig Extension
The bundle provides a Twig extension for generating a QR code URL, path or data URI. You can use the second argument to specify the builder to use.
<img src="{{ qr_code_path('My QR Code') }}" /> <img src="{{ qr_code_url('My QR Code') }}" /> <img src="{{ qr_code_data_uri('My QR Code') }}" /> {# You can specify the builder via the second parameter #} <img src="{{ qr_code_data_uri('My QR Code', 'custom') }}" /> {# You can access the width and height via the matrix #} {% set qrCode = qr_code_result('My QR Code') %} <img src="{{ qrCode.dataUri }}" width="{{ qrCode.matrix.outerSize }}" />
Please note that some Twig functions need the route to be enabled to function.
Versioning
Version numbers follow the MAJOR.MINOR.PATCH scheme. Backwards compatibility breaking changes will be kept to a minimum but be aware that these can occur. Lock your dependencies for production and test your code when upgrading.
License
This source code is subject to the MIT license bundled in the file LICENSE.
endroid/qr-code-bundle 适用场景与选型建议
endroid/qr-code-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.4M 次下载、GitHub Stars 达 325, 最近一次更新时间为 2018 年 01 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「php」 「bundle」 「code」 「endroid」 「qr」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 endroid/qr-code-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 endroid/qr-code-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 endroid/qr-code-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
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.
DMS Meetup API Bundle, enables Meetup API clients in services
Bundle Symfony DaplosBundle
Provides a Data Grid tables for your Symfony project.
统计信息
- 总下载量: 11.4M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 327
- 点击次数: 56
- 依赖项目数: 21
- 推荐数: 2
其他信息
- 授权协议: MIT
- 更新时间: 2018-01-02