pgs-soft/hashid-bundle

Symfony Hash Id

维护者

详细信息

github.com/PGSSoft/HashId

源代码

问题

安装数: 10,030

依赖: 0

建议者: 0

安全性: 0

星标: 12

关注者: 4

分支: 3

开放性问题: 8

类型:symfony-bundle

v3.1.0 2023-04-27 03:12 UTC

README

PHP from Packagist Build Status Code Coverage Scrutinizer Code Quality

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 维护。查看我们的其他 开源项目联系我们 以开发您的产品。

关注我们

Twitter URL Twitter Follow