承接 delolmo/valinor-console 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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-console will always match cuyz/valinor versions. 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 allowSuperfluousKeys is not used, the mapping process will throw an exception - unless you consider these parameters in the object you are trying to map (App\DTO\CustomObject in 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 enableFlexibleCasting should also be configured in the Mapper. See Enabling flexible casting for more information.

统计信息

  • 总下载量: 760
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2023-01-29

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固