delolmo/valinor-console
最新稳定版本:2.3
Composer 安装命令:
composer require delolmo/valinor-console
包简介
Use symfony/console as a Valinor source
README 文档
README
The following library allows using InputInterface objects of the symfony/console component as a source for the cuyz/valinor library.
Installation
composer require delolmo/valinor-console
Example
use App\DTO\CustomObject; use CuyZ\Valinor\Mapper\Source\Source; use CuyZ\Valinor\MapperBuilder; use DelOlmo\Valinor\Mapping\Source\InputSource; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; final class CustomCommand extends Command { public function execute(InputInterface $input, OutputInterface $output): int { // Create the Source using the new InputSource $source = Source::iterable(new InputSource($input)); // Create the Mapper, using the desired configuration $mapper = new MapperBuilder()) ->allowSuperfluousKeys() ->enableFlexibleCasting() ->mapper(); // Map the source to whatever object makes sense $mapped = $mapper->map(CustomObject::class, $source); // Apply whatever business logic makes sense from here // ... } }
Final notes
- Versioning of
delolmo/valinor-consolewill always matchcuyz/valinorversions. Same goes for PHP versions. - When creating the Mapper object, it should always be taken into account that, by default, Symfony adds several options to the InputInterface object (i.e., help or verbosity levels). If
allowSuperfluousKeysis not used, the mapping process will throw an exception - unless you consider these parameters in the object you are trying to map (App\DTO\CustomObjectin the above example). See Allow superflous keys for more information. - Although options and arguments cannot share the same name within the same Symfony command, it should be noted that, from an InputSource standpoint, arguments always take precedence over options. That is, if there is an argument and an option sharing the same name, InputSource will only use the argument's value for mapping purposes.
- Considering that Symfony command applications convert most of the fields to either strings or arrays, it is interesting to note that
enableFlexibleCastingshould also be configured in the Mapper. See Enabling flexible casting for more information.
统计信息
- 总下载量: 760
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2023-01-29