mrgoodbytes8667/enum-serializer-bundle
Composer 安装命令:
composer require mrgoodbytes8667/enum-serializer-bundle
包简介
A bundle to enable spatie/enum Serialization support in Symfony
README 文档
README
A bundle to provide some helper methods for PHP 8.1+ enums inspired by spatie/enum
Upgrading to 6.0 from 5.x
- The EnumNormalizer will no longer be registered as a service by default. You must manually enable it to continue using it. It will be removed in v7.
Upgrading to 4.0 from 3.x
- Replace any usages of
Bytes\EnumSerializerBundle\Request\EnumParameterConverterwith ValueResolvers. See https://symfony.com/doc/current/controller/value_resolver.html
Upgrading to 3.0 from 2.x
- Replace the deprecated calls to
easyAdminChoices()andformChoices()withprovideFormChoices(). - Upgrade any overridden versions of
provideFormChoices(),getFormChoiceKey(), andgetFormChoiceValue()fromprotectedtopublic.
Upgrading to 2.0
Change all classes that extend Bytes\EnumSerializerBundle\Enums\Enum to be string backed enums, using the new
Bytes\EnumSerializerBundle\Enums\StringBackedEnumTrait trait and implementing the new
Bytes\EnumSerializerBundle\Enums\StringBackedEnumInterface interface.
Bytes\EnumSerializerBundle\Enums\StringBackedEnumTraitprovides the previousEnumclass methods that are still relevant and needed with the switch to enums, including ajsonSerializable()method to keep serialization consistent.Bytes\EnumSerializerBundle\Enums\StringBackedEnumInterfacemust be implemented (or\JsonSerializable) in order to have the serializer properly return label/value as it did prior to 2.0.- Note:
Bytes\EnumSerializerBundle\Enums\StringBackedEnumInterfaceextends bothBytes\EnumSerializerBundle\Enums\EasyAdminChoiceEnumInterfaceandBytes\EnumSerializerBundle\Enums\FormChoiceEnumInterface, which both automatically provide EasyAdminBundle and Symfony form compatible choice methods and are easily overloadable.
Before
<?php namespace Bytes\EnumSerializerBundle\Tests\Fixtures; use Spatie\Enum\Enum; /** * @method static self streamChanged() * @method static self userChanged() */ class ValuesEnum extends Enum { /** * @return string[] */ protected static function values(): array { return [ 'streamChanged' => 'stream', 'userChanged' => 'user', ]; } }
After
<?php namespace Bytes\EnumSerializerBundle\Tests\Fixtures; use Bytes\EnumSerializerBundle\Enums\StringBackedEnumInterface; use Bytes\EnumSerializerBundle\Enums\StringBackedEnumTrait; enum ValuesEnum: string implements StringBackedEnumInterface { use StringBackedEnumTrait; case streamChanged = 'stream'; case userChanged = 'user'; }
With Optional Deprecated Replacement for PHPStorm
<?php namespace Bytes\EnumSerializerBundle\Tests\Fixtures; use Bytes\EnumSerializerBundle\Enums\StringBackedEnumInterface; use Bytes\EnumSerializerBundle\Enums\StringBackedEnumTrait; use JetBrains\PhpStorm\Deprecated; enum ValuesEnum: string implements StringBackedEnumInterface { use StringBackedEnumTrait; case streamChanged = 'stream'; case userChanged = 'user'; #[Deprecated(reason: 'since 1.7.0, use "%name%" instead.', replacement: '%class%::%name%')] public static function streamChanged(): ValuesEnum { return ValuesEnum::streamChanged; } #[Deprecated(reason: 'since 1.7.0, use "%name%" instead.', replacement: '%class%::%name%')] public static function userChanged(): ValuesEnum { return ValuesEnum::userChanged; } }
Note that the automated replacement will not remove the trailing () following the function
Installation
Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.
Applications that use Symfony Flex
Open a command console, enter your project directory and execute:
$ composer require mrgoodbytes8667/enum-serializer-bundle
Applications that don't use Symfony Flex
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require mrgoodbytes8667/enum-serializer-bundle
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the config/bundles.php file of your project:
// config/bundles.php return [ // ... Bytes\EnumSerializerBundle\BytesEnumSerializerBundle::class => ['all' => true], ];
License
Inspired by and based on the spatie/enum package.
mrgoodbytes8667/enum-serializer-bundle 适用场景与选型建议
mrgoodbytes8667/enum-serializer-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 98.2k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 10 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 mrgoodbytes8667/enum-serializer-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mrgoodbytes8667/enum-serializer-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 98.2k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 10
- 依赖项目数: 8
- 推荐数: 0
其他信息
- 授权协议: CC-BY-NC-4.0
- 更新时间: 2020-10-22