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
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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 zepekegno/obfuscate-id-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
2lenet/EasyAdminPlusBundle
The bundle for easy using json-rpc api on your project
Provide a way to secure accesses to all routes of an symfony application.
DMS Meetup API Bundle, enables Meetup API clients in services
Provides hash tools for Laravel.
Replaces the default email address spam protection with a better one. The email obfuscation is more randomized, safer and more user friendly for the website visitor.
统计信息
- 总下载量: 49
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-28