galactic-shrine/gsid 问题修复 & 功能扩展

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

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

galactic-shrine/gsid

Composer 安装命令:

composer require galactic-shrine/gsid

包简介

GsId 256-bit identifier system for Galactic-Shrine projects.

README 文档

README

Langues : Français · English · Español · Italiano · 日本語

GsId est une bibliothèque PHP pour créer, parser, valider, sérialiser et stocker des identifiants Galactic-Shrine de 256 bits.

Elle fournit un cœur PHP pur, un type Doctrine DBAL, un bundle Symfony optionnel, un bridge Symfony et une recipe Symfony Flex prête à publier.

Vue d’ensemble

Élément Valeur
Package galactic-shrine/gsid
Version majeure 2.0.1
PHP >= 8.1
Licence MPL-2.0
Type d’identifiant 256 bits / 32 octets / 64 caractères hexadécimaux
Format Doctrine gsid
Bundle Symfony GalacticShrine\GsId\Symfony\GsIdBundle

Installation

composer require galactic-shrine/gsid:^2.0

Formats supportés

GsId supporte deux formats texte.

Format N

Format compact, sans séparateur :

0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef

Longueur : 64 caractères.

Format D

Format lisible avec séparateurs :

0123456789abcdef-01234567-89abcdef-01234567-89abcdef-0123456789abcdef

Groupe : 16-8-8-8-8-16.

Longueur : 69 caractères.

Utilisation PHP pure

use GalacticShrine\GsId\GsId;
use GalacticShrine\GsId\GsIdCase;
use GalacticShrine\GsId\GsIdFormat;
use GalacticShrine\GsId\GsIdValidator;

$id = GsId::newGsId();

echo $id->toString(GsIdFormat::N, GsIdCase::Lower);
echo $id->toString(GsIdFormat::D, GsIdCase::Upper);

$parsed = GsId::fromString((string) $id);

if (GsIdValidator::isValid((string) $id)) {
    // Identifiant valide.
}

Options globales

use GalacticShrine\GsId\GsIdCase;
use GalacticShrine\GsId\GsIdFormat;
use GalacticShrine\GsId\GsIdOptions;

GsIdOptions::configure(
    defaultCase: GsIdCase::Lower,
    defaultTextFormat: GsIdFormat::N,
    defaultJsonFormat: GsIdFormat::D,
    defaultDatabaseFormat: GsIdFormat::N,
);

GsIdOptions::lock();

lock() empêche les modifications de configuration après l’initialisation de l’application.

Symfony avec bundle

Active le bundle si Symfony Flex ne le fait pas automatiquement :

// config/bundles.php
return [
    GalacticShrine\GsId\Symfony\GsIdBundle::class => ['all' => true],
];

Configuration recommandée :

# config/packages/gsid.yaml
gsid:
    default_case: Lower
    default_text_format: N
    default_json_format: D
    default_database_format: N
    lock: true

Le bundle enregistre automatiquement le type Doctrine DBAL gsid si DoctrineBundle est présent.

Symfony sans bundle

Le fichier suivant est fourni comme configuration alternative :

config/services.gsid.yaml

Il permet d’enregistrer manuellement :

GalacticShrine\GsId\Symfony\GsIdOptionsConfigurator

Ce mode est utile si tu veux utiliser Symfony sans activer GsIdBundle.

Doctrine DBAL

Depuis 2.0.0, le type Doctrine est dans le namespace bridge :

use GalacticShrine\GsId\Bridge\Doctrine\Types\GsidType;

Exemple d’entité :

use Doctrine\ORM\Mapping as ORM;
use GalacticShrine\GsId\Bridge\Doctrine\Types\GsidType;
use GalacticShrine\GsId\GsId;

#[ORM\Entity]
final class ExampleEntity
{
    #[ORM\Id]
    #[ORM\Column(type: GsidType::Name, unique: true)]
    private ?GsId $id = null;
}

Tu peux aussi utiliser directement le nom du type :

#[ORM\Column(type: 'gsid')]
private ?GsId $id = null;

Bridge Symfony

GsIdToUid fournit des conversions utiles pour les routes, DTO, formulaires ou serializers Symfony.

use GalacticShrine\GsId\Symfony\Bridge\GsIdToUid;

$value = GsIdToUid::normalizeForRoute($id);
$id = GsIdToUid::denormalizeFromRoute($value);

Le nom GsIdToUid est volontaire. GsIdToUuid serait trompeur, car un GsId est un identifiant 256 bits alors qu’un UUID standard est un identifiant 128 bits.

Symfony Flex recipe

Une recipe modèle est fournie ici :

flex-recipes/galactic-shrine/gsid/2.0/

Elle peut :

  • activer GsIdBundle ;
  • copier config/packages/gsid.yaml dans le projet Symfony utilisateur.

Important : le dossier flex-recipes/ inclus dans ce dépôt est un modèle. Pour que Symfony Flex l’applique automatiquement lors d’un composer require, la recipe doit être publiée dans un dépôt Symfony Flex public ou privé.

Migration depuis 1.x

GsIdDoctrineType a été supprimé en 2.0.0.

Avant :

GalacticShrine\GsId\GsIdDoctrineType

Après :

GalacticShrine\GsId\Bridge\Doctrine\Types\GsidType

Voir UPGRADE-2.0.md.

Guides de migration disponibles : FR, EN, ES, IT, JP.

Développement

composer install
composer lint
composer test

Licence

GsId is distributed under MPL-2.0.

galactic-shrine/gsid 适用场景与选型建议

galactic-shrine/gsid 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 21 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 galactic-shrine/gsid 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MPL-2.0
  • 更新时间: 2026-04-12