承接 stoyantodorov/resolve-utilities 相关项目开发

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

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

stoyantodorov/resolve-utilities

最新稳定版本:1.0.0

Composer 安装命令:

composer require stoyantodorov/resolve-utilities

包简介

Laravel Package

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package offers a way to instantiate a class, to send typed input to it and to receive typed result using a convenient interface:

public function useUtility(string $abstract, array $input): mixed

That is implemented by Resolver class. It takes care to there are no duplicated instances and resets input/output in them before using.
The instantiated class should extend StoyanTodorov\ResolveUtilities\Utility - so it is obliged to implement method execute:

abstract public function execute(): self

Тhe data sent to useUtility through array $input is available as class properties in the instance. The output, that we expect, should be set in output property. In this way we may rely on typed input and output without binding the executed code to a certain interface.

Requirements

  • PHP 8.1

  • Laravel

Installation

composer require stoyantodorov/resolve-utilities

Usage

Extend Utility
use StoyanTodorov\ResolveUtilities\Utility;

class StringOutputExample extends Utility
{
    protected string $output;

    protected string|null $propOne = null;
    protected int|null $propTwo = null;
    
    protected array $requiredInput = ['propOne'];
    protected array $defaultInput = ['propTwo' => 1];

    public function execute(): Utility
    {
        $this->output = $this->propOne;

        return $this;
    }
}
  • In requiredInput add the properties names which execute uses.
  • In defaultInput add the properties names with theirs default values. When useUtility method is called these values are used unless they aren't added to the second parameter.

Resolver

$resolver = new StoyanTodorov\ResolveUtilities\Resolver;
$resultOne = $resolver->useUtility(StringOutputExample::class, ['propOne' => 'test']);
$resultTwo = $resolver->useUtility(StringOutputExample::class, ['propOne' => 'test', 'propTwo' => 100]);
  • The first parameter sent to useUtility may also be an abstract definition like 'single-output-example'. It will be instantiated if there is such definition in Laravel Service Container

HasResolver

use StoyanTodorov\ResolveUtilities\HasResolver;

class ExampleClient 
{
    use HasResolver;
    
    public function test(string $propOne): string
    {
        return $this->useUtility(StringOutputExample::class, compact('propOne'));
    }
}
$result = (new ExampleClient)->test('test');

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-10-23