ex3v / myclabs-enum-param-converter
dev-master / 0.0.1.x-dev
2019-05-15 15:14 UTC
Requires
- php: ^7.0
- myclabs/php-enum: ^1.2
- sensio/framework-extra-bundle: ^3.0|^4.0|^5.0
Requires (Dev)
- phpunit/phpunit: ^5.4|^6.0
- symfony/phpunit-bridge: ~2.7
This package is auto-updated.
Last update: 2024-09-16 03:22:01 UTC
README
这是一个简单的 Symfony 扩展包,允许在控制器中无缝地启用 MyClabs\Enum
参数转换。
安装和用法
1. 使用 composer 安装
composer require ex3v/myclabs-enum-param-converter
2. 启用扩展包
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new \Ex3v\MyCLabsEnumParamConverterBundle\MyCLabsEnumParamConverterBundle(), ); }
3. 在控制器中使用
/** * @ParamConverter("barType") */ public function fooAction(BarType $barType) : Response { //... }
注意,只要在控制器操作中使用类型提示,您不需要指定特定的转换器。
如果您想明确指定此转换器,请参考以下示例
/** * @ParamConverter("barType", converter="converter_enum") */ public function fooAction(BarType $barType) : Response { //... }