Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

优化格式化类配置 #83

Closed
wants to merge 1 commit into from
Closed

优化格式化类配置 #83

wants to merge 1 commit into from

Conversation

guanguans
Copy link
Contributor

@guanguans guanguans commented Dec 30, 2022

新增了一个 make 函数,类似 laravel 的 app()->make() 的方法。

格式化类的创建由数字下标获取参数创建改为参数名称获取。这样更改更具有表达力和普适性。例如自定义的类没有依赖、或者依赖是可注入的,直接配置该类依然是适用的。

'format' => MyFormat::class,

*/
function make($abstract, array $parameters = [])
{
if (! in_array(gettype($abstract), ['string', 'array'])) {
Copy link
Owner

@jiannei jiannei Dec 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我觉得这里的逻辑可以移到 LaravelServiceProvider 中,不需要额外暴露一个 make 函数;另外,config/response.php中的 format 配置项可以固定格式,string 类型则必须是实现了Jiannei\Response\Laravel\Contracts\Format的 class ,array 类型则必须包含 class、config 2个key。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

差不多这样子。不过数组类型的配置应该是 class 和该类构造方法的参数名称。尽量不要固定为config。

@guanguans guanguans closed this Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants