sbsedv / input-converter-bundle
一个用于将原始请求数据添加到 http-foundation InputBag 的 Symfony ^6.1 包。
Requires
- php: >=8.1
- sbsedv/input-converter: ^3.0
- symfony/framework-bundle: ^6.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.13
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^1.4
- phpstan/phpstan-symfony: ^1.1
README
sbsedv/input-converter-bundle
一个添加原始请求数据到 http-foundation InputBag 的 Symfony ^6.1 包。
composer require sbsedv/input-converter-bundle
此包将 sbsedv/input-converter 集成到 Symfony 框架 中。
此包注册了一个事件监听器,它在应用生命周期中尽可能早地运行,并尝试解析传入的请求数据并将其添加到主要的 http-foundation 请求对象。
默认情况下,此包包含以下转换器,它们都默认启用:
# config/packages/sbsedv_input_converter.yaml # Default configuration values are shown sbsedv_input_converter: # {NAME}_converter: false # disables the {NAME} converter json_converter: content_types: [application/json] # Http Content-Type headers on which this converter will work methods: [POST, PUT, PATCH, DELETE] # Http Methods on which this convert will work formdata_converter: methods: [PUT, PATCH, DELETE] file_support: false # Whether file uploads are added to the FileBag urlencoded_converter: enabled: false # disabled by default, see below methods: [PUT, PATCH, DELETE]
警告:您不应为 formdata_converter
启用 file_support
。
整个上传的文件至少会被复制到内存中两次,这将可能使用大量的系统内存(取决于文件大小)。PHP 的 upload_max_filesize
INI 设置没有效果,只有 post_max_size
。
您应仅依赖 PHP 集成的文件上传支持。
自定义转换器
如果您想注册一个自定义转换器(例如,为 YAML 支持),您只需在您的应用程序中注册一个实现 SBSEDV\InputConverter\Converter\ConverterInterface
的服务即可。
该包有自动配置设置,每个实现该接口的服务都会自动被选中。
URLEncodedConverter 信息
默认情况下,urlencoded_converter
被禁用,因为 Symfony\Component\HttpFoundation\Request::createFromGlobals()
有相同的功能。
绝大多数 symfony 应用程序以创建 Request 对象的方式启动框架,使用这个静态方法。因为这个原因,该包默认禁用其功能,以避免不必要的操作。
如果您在未调用此方法的情况下启动 symfony(例如,在 Swoole 运行时中),您可以在包的配置文件中手动启用该功能。