定制 mitch/hashids 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mitch/hashids

Composer 安装命令:

composer require mitch/hashids

包简介

Laravel package for Hashids

README 文档

README

This package uses the classes created by hashids.org

Generate hashes from numbers, like YouTube or Bitly. Use hashids when you do not want to expose your database ids to the user.

Installation

Begin by installing the package through Composer. Edit your project's composer.json file to require mitch/hashids.

"require": {
  "mitch/hashids": "1.x"
}

Next use Composer to update your project from the the Terminal:

php composer.phar update

Once the package has been installed you'll need to add the service provider. Open your app/config/app.php configuration file, and add a new item to the providers array.

'Mitch\Hashids\HashidsServiceProvider'

After doing this you also need to add an alias. In your app/config/app.php file, add this to the aliases array.

'Hashids' => 'Mitch\Hashids\Hashids'

Now last but not least you need to publish to package configuration from your Terminal:

php artisan config:publish mitch/hashids

Usage

Once you've followed all the steps and completed the installation you can use Hashids.

Encoding

You can simply encrypt on id:

Hashids::encode(1); // Creating hash... Ri7Bi

or multiple..

Hashids::encode(1, 21, 12, 12, 666); // Creating hash... MMtaUpSGhdA

Decoding

It's the same thing but the other way around:

Hashids::decode('Ri7Bi');

// Returns
array (size=1)
  0 => int 1

or multiple..

Hashids::decode('MMtaUpSGhdA');

// Returns
array (size=5)
  0 => int 1
  1 => int 21
  2 => int 12
  3 => int 12
  4 => int 666

Injecting Hashids

Now it's also possible to have Hashids injected into your class. Lets look at this controller as an example..

class ExampleController extends BaseController
{
    protected $hashids;

    public function __construct(Hashids\Hashids $hashids)
    {
        $this->hashids = $hashids;
    }

    public function getIndex()
    {
        $hash = $this->hashids->encode(1);
        return View::make('example.index', compact('hash'));
    }
}

The original classname and namespace has been bound in the IoC container to return our instantiated Hashids class.

Using IoC

Create a Hashids instance with the IoC

App::make('Hashids\Hashids')->encode(1);

That's it!

Documentation about Hashids can be found here.

Thanks to Ivan Akimov (@ivanakimov) for making Hashids. All credits for the Hashids package go to him.

mitch/hashids 适用场景与选型建议

mitch/hashids 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 112.33k 次下载、GitHub Stars 达 105, 最近一次更新时间为 2013 年 04 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 mitch/hashids 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mitch/hashids 我们能提供哪些服务?
定制开发 / 二次开发

基于 mitch/hashids 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 112.33k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 105
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 105
  • Watchers: 3
  • Forks: 21
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2013-04-27