zepekegno/obfuscate-id-bundle 问题修复 & 功能扩展

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

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

zepekegno/obfuscate-id-bundle

Composer 安装命令:

composer require zepekegno/obfuscate-id-bundle

包简介

Symfony bundle to securely obfuscate and deobfuscate entity IDs in URLs. Provides attributes and Twig filters to handle obfuscation seamlessly within Symfony applications.

README 文档

README

Latest Stable Version Total Downloads License PHP Version Require

Introduction

ObfuscateIdBundle is a Symfony extension that enables obfuscation of identifiers in URLs and API responses. This new version introduces several improvements, including:

  • Automatic obfuscation of IDs when loading fixtures with Doctrine
  • Support for dynamic properties via the #[ObfuscateId] annotation
  • Improved Twig filters
  • Persistent default key generation when no key is provided
  • Preserved compatibility with both entity-based and raw ID controller actions

Installation

Install the bundle via Composer:

composer require zepekegno/obfuscate-id-bundle

Then, activate it in bundles.php if not automatically enabled:

return [
    Zepekegno\ObfuscateIdBundle\ObfuscateIdBundle::class => ['all' => true],
];

Configuration

Add the following configuration in config/packages/obfuscate_id.yaml:

obfuscate_id:
    secret_key: '%env(OBFUSCATE_ID_SECRET)%'

Define the environment variables in .env:

OBFUSCATE_ID_SECRET="your_secret_key"

If OBFUSCATE_ID_SECRET is not defined, the bundle will automatically generate a persistent default secret key at installation time. This ensures a consistent encryption key across application restarts and deployments.

The persistent IV will also be generated.

Usage

1. Obfuscation in Controllers

Obfuscation is now automatic, meaning you no longer need to manually annotate route parameters. The bundle will automatically deobfuscate IDs in controller actions:

use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Response;

#[Route('/user/{id}', name: 'user_show')]
public function show(int $id): Response
{
    return new Response("Deobfuscated ID: " . $id);
}

For entity-based routes, it automatically resolves the entity:

#[Route('/user/{id}', name: 'user_show')]
public function show(User $user): Response
{
    return new Response("User: " . $user->getId());
}

You may also use the annotation explicitly to control deobfuscation:

use Zepekegno\ObfuscateIdBundle\ValueResolver\Attribute\ObfuscateId;

#[Route('/user/{id}', name: 'user_show')]
public function show(#[ObfuscateId(entity: User::class)] User $user): Response
{
    return new Response("User: " . $user->getId());
}

2. Automatic Obfuscation of IDs in Doctrine

When an entity is loaded, its ID is automatically obfuscated. Add the #[Obfuscate] annotation to the relevant property:

use Zepekegno\ObfuscateIdBundle\Attribute\Obfuscate;

#[ORM\Entity]
class User
{
    #[ORM\Id, ORM\GeneratedValue, ORM\Column(type: 'integer')]
    #[Obfuscate] // This property will be automatically obfuscated
    private ?int $id = null;
}

3. Using Obfuscation in Twig

Use the obfuscate filter to mask an identifier in a template:

<a href="{{ path('user_show', { id: user.id|obfuscate }) }}">View User</a>

Doctrine Events

The bundle listens for the following events:

  • postLoad → Automatically applies obfuscation to loaded entities.

Development

Install dependencies:

## Contributing

1. Fork the repository
2. Clone your fork
3. Create your feature branch: `git checkout -b feature/YourFeature`
4. Commit your changes: `git commit -am 'Add new feature'`
5. Push to the branch: `git push origin feature/YourFeature`
6. Create a new Pull Request

### Guidelines

- Ensure test coverage for your changes.
- Follow PSR coding standards.
- Prefer small, focused pull requests.

Support

If you encounter any issues, open an issue on GitHub. For feature requests, please provide a detailed description of the use case and expected behavior.

zepekegno/obfuscate-id-bundle 适用场景与选型建议

zepekegno/obfuscate-id-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 49 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 10 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「symfony」 「bundle」 「id」 「obfuscate」 「zepekegno」 「offusquer」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 zepekegno/obfuscate-id-bundle 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-10-28