jasonbradley/hash-ids-bundle

Symfony2 Bundle 用于访问 HashIds 库,以便从整数生成短唯一ID - http://hashids.org/php/

安装次数: 3,981

依赖者: 0

建议者: 0

安全性: 0

星标: 0

关注者: 2

分支: 1

开放问题: 1

类型:symfony-bundle

0.1.1 2015-08-05 19:03 UTC

This package is not auto-updated.

Last update: 2024-09-28 17:54:43 UTC


README

Symfony2 bundle,用于访问 HashIds 库,以便从整数生成短唯一ID

"Hashids 是一个小的开源库,可以从数字生成短、唯一、非顺序的ID。它将数字如347转换为字符串如“yr8”,或将数字数组如[27, 986]转换为“3kTMd”。您还可以解码这些ID。这在将多个参数组合到一个或简单地用作短UID时非常有用。"

1. 在 composer.json 中包含

"jasonbradley/hash-ids-bundle": "dev-master"

2. 在 AppKernel.php 中包含

new JasonBradley\HashIdsBundle\JasonBradleyHashIdsBundle()

3. Bundle 配置示例(config.yml)

jason_bradley_hash_ids:
    salt: abc123
    min_hash_length: 25
    alphabet: "abcdefghijklmnopqrstuvwxyz"

要使用此服务

$hash = $this->get('hash_ids')
            ->encode(123);

$numbers = $this->get('hash_ids')
    ->decode($hash);