roukmoute/hashids-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

roukmoute/hashids-bundle

最新稳定版本:v3.1.0

Composer 安装命令:

composer require roukmoute/hashids-bundle

包简介

Integrates hashids/hashids in a Symfony project

README 文档

README

SymfonyInsight Scrutinizer Code Quality Packagist Downloads

HashidsBundle

Integrates hashids/hashids in a Symfony project.

Installation using composer

These commands requires you to have Composer installed globally.
Open a command console, enter your project directory and execute the following commands to download the latest stable version of this bundle:

Using Symfony Flex

 composer config extra.symfony.allow-contrib true composer req roukmoute/hashids-bundle 

Using Symfony Framework only

 composer require roukmoute/hashids-bundle 

If this has not been done automatically, enable the bundle by adding the following line in the config/bundles.php file of your project:

<?php return [ …, Roukmoute\HashidsBundle\RoukmouteHashidsBundle::class => ['all' => true], ];

Configuration

The configuration (config/packages/roukmoute_hashids.yaml) looks as follows :

roukmoute_hashids: # if set, the hashids will differ from everyone else's salt: "" # if set, will generate minimum length for the id # 0 — meaning hashes will be the shortest possible length min_hash_length: 0 # if set, will use only characters of alphabet string alphabet: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" # if set to true, it will continue with the next available param converters passthrough: false # if set to true, it tries to convert all arguments passed to the controller auto_convert: false

Usage

use Hashids\HashidsInterface; public function postShow(HashidsInterface $hashids): Response { $hashids-> }

Next it's the same things of official documentation.

Hashids Converter

Converter Name: hashids.converter

The hashids converter attempts to convert any attribute set in the route into an integer parameter.

You could use hashid or id:

/**  * @Route("/users/{hashid}")  */ public function getAction(int $user) { }

or

/**  * @Route("/users/{id}")  */ public function getAction(int $user) { }

You could have several hashids in the same URL prefixed with _hash_.

/**  * @Route("/users/{_hash_user}/status/{_hash_status}")  */ public function getAction(int $user, int $status) { }

The keys must be the same as in parameters controller:

/**  * _hash_user _hash_status  * ↕ ↕  * public function getAction(int $user, int $status)  */

You will receive a LogicException if a hash could not be decoded correctly.

Using auto_convert

auto_convert tries to convert all arguments in controller.

roukmoute_hashids: auto_convert: true

Base on the example above:

/**  * @Route("/users/{user}/status/{status}")  */ public function getAction(int $user, int $status) { }

It will not be possible to get an exception of type LogicException from the bundle if it is activated.

Using passthrough

passthrough allows to continue with the next available param converters.
So if you would like to retrieve an object instead of an integer, just active passthrough :

roukmoute_hashids: passthrough: true

Base on the example above:

/**  * @Route("/users/{hashid}")  */ public function getAction(User $user) { }

As you can see, the passthrough feature allows to use DoctrineParamConverter or any another ParamConverterInterface you would have created.

Twig Extension

Usage

{{ path('users.show', {'hashid': user.id | hashids_encode }) }} {{ app.request.query.get('hashid') | hashids_decode }}

统计信息

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

GitHub 信息

  • Stars: 45
  • Watchers: 2
  • Forks: 16
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固