pgs-soft / hashid-bundle
Symfony Hash Id
v3.1.0
2023-04-27 03:12 UTC
Requires
- php: >=7.2.5
- doctrine/annotations: ^1.6
- hashids/hashids: >=2.0
- symfony/config: ~4.4|~5.0
- symfony/dependency-injection: ^4.1.12|^5.0
- symfony/routing: ^5.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.10
- phpstan/phpstan: ^0.12
- phpunit/phpunit: ^7.0
- sebastian/phpcpd: ^4.0
- sensio/framework-extra-bundle: ^5.1
- squizlabs/php_codesniffer: ^3.2
- symfony/browser-kit: ^4.0
- symfony/http-kernel: ^4.4.13|^5.1.5
- symfony/yaml: ^4.0
This package is auto-updated.
Last update: 2024-08-27 06:34:24 UTC
README
Symfony 扩展包,用于使用 http://www.hashids.org/ 对整数路由参数进行编码和解码
请使用此版本与 Symfony ≥5.0 配合使用
以简单的方式替换可预测的整数 URL 参数
/hash-id/demo/decode/216/30
=>/hash-id/demo/decode/X46dBNxd79/30
/order/315
=>/order/4w9aA11avM
优点
- 无需使用额外的过滤器 - 在 twig 模板中使用
{{ url('route_name', {'id': 1}) }}
,或在控制器或服务中使用$this->generateUrl('route_name', ['id' => 1]);
- Doctrine 转换器 兼容
安装
composer require pgs-soft/hashid-bundle
Hashids 配置
# config/packages/pgs_hash_id.yaml pgs_hash_id: converter: hashids: salt: 'my super salt' min_hash_length: 20 alphabet: 'qwertyasdzxc098765-'
控制器配置
use Pgs\HashIdBundle\Annotation\Hash; class UserController extends Controller { /** * @Hash("id") */ public function edit(int $id) { //... } /** * Process multiple parameters - 'oneMore' will not be processed * @Route(name="test", path="/test/{id}/{other}/{oneMore}") * @Hash({"id","other"}) */ public function test(int $id, int $other, int $oneMore) { //... } }
您还可以查看我们的 DemoController。
贡献
欢迎在 GitHub 上提交错误报告和拉取请求 https://github.com/PGSSoft/HashId。
关于
该项目由 软件开发机构 PGS Software 维护。查看我们的其他 开源项目 或 联系我们 以开发您的产品。