定制 lokhman/silex-hashids 二次开发

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

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

lokhman/silex-hashids

Composer 安装命令:

composer require lokhman/silex-hashids

包简介

Silex 2.0+ service provider for Hashids library

README 文档

README

StyleCI

Hashids Service provider for Silex 2.0+ micro-framework.

This project is a part of silex-tools library.

Installation

You can install silex-hashids with Composer:

composer require lokhman/silex-hashids

Documentation

Enable HashidsServiceProvider from Provider namespace to support brilliant Hashids library. You may setup either a single or multiple profiles to use in your application.

use Lokhman\Silex\Provider\HashidsServiceProvider;

$app->register(new HashidsServiceProvider(), [
    // default options for all profiles
    'hashids.options' => [
        'salt' => '',
        'min_length' => 0,
        'alphabet' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890',
    ],
    // optionally set multiple profiles
    'hashids.profiles' => [
        'profile1' => [
            'min_length' => 8,
        ],
        'profile2' => [
            'salt' => 'this is my salt',
            'alphabet' => 'abcdefghijklmnopqrstuvwxyz',
        ],
    ],
]);

// single profile encoding
$hash = $app['hashids']->encode(1, 2, 3);
$app['hashids']->encode(1, 2, 3) === $hash;
$app->hashids([1, 2, 3]) === $hash;

// single profile decoding
$id = $app['hashids']->decode($hash);
$app['hashids']->decode($hash) === $id;
$app->hashids($hash) === $id;

// multiple profiles encoding
$hash = $app['hashids']['profile1']->encode(1, 2, 3);
$app['hashids:profile1']->encode(1, 2, 3) === $hash;
$app->hashids([1, 2, 3], 'profile1') === $hash;

// multiple profiles decoding
$id = $app['hashids']['profile1']->decode($hash);
$app['hashids:profile1']->decode($hash) === $id;
$app->hashids($hash, 'profile1') === $id;

N.B.: To use hashids() application method, include HashidsTrait to your Application class. This method returns FALSE on error, and if given hash contains a single encoded id, integer is returned, otherwise array.

Additionally, the service provider adds support for auto-conversion of hashed parameters in routes if you specify them with __hashids_ prefix.

// GET /users/jR (single profile)
$app->get('/users/{__hashids_id}', function(Application $app, $id) {
    return $app->json(['id' => $id]);  // { "id": 1 }
});

// GET /users/olejRejN (multiple profiles)
$app->get('/users/{__hashids_profile1_id}', function(Application $app, $id) {
    return $app->json(['id' => $id]);  // { "id": 1 }
});

License

Library is available under the MIT license. The included LICENSE file describes this in detail.

统计信息

  • 总下载量: 332
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 1

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-01-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固