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

mix-skeleton使用context()->get('guzzle') 报错 #84

Closed
liushzhql opened this issue Sep 8, 2020 · 1 comment
Closed

mix-skeleton使用context()->get('guzzle') 报错 #84

liushzhql opened this issue Sep 8, 2020 · 1 comment

Comments

@liushzhql
Copy link

liushzhql commented Sep 8, 2020

System         Name:      alpine3.9
PHP            Version:   7.3.13
Swoole         Version:   4.5.2
Skeleton       Version:   2.2.12
  • 复现代码:
$client = context()->get('guzzle');
  • Guzzle client报错:
handler must be a callable
  • 暂时解决办法:
    修改bean文件,将ref依赖注入改为直接传入handler实例
    /mix/manifest/beans/guzzle.php
<?php

return [

    // Guzzle
    [
        // 名称
        'name'            => 'guzzle',
        // 类路径
        'class'           => \GuzzleHttp\Client::class,
        // 构造函数注入
        'constructorArgs' => [
            // config
            [
                'handler' => new \Mix\Guzzle\Handler\StreamHandler,
            ],
        ],
    ],
    
];
@onanying
Copy link
Member

onanying commented Sep 8, 2020

@liushzhql https://github.com/mix-php/guzzle 的新版本其实已经不需要指定 handler 了, 安装即hook,这里确实有问题,因为设计依赖注入的时候构造参数本身是支持 ref 引用,但是这里是 $config 里面了,是不支持引用的,所以抛出异常,这里我忽略了,新的骨架将移除 handler 的配置,因为其实已经不需要了

// Guzzle
[
    // 名称
    'name'            => 'guzzle',
    // 类路径
    'class'           => \GuzzleHttp\Client::class,
    // 构造函数注入
    'constructorArgs' => [
        // config
        [
            'handler' => ['ref' => Mix\Guzzle\Handler\StreamHandler::class],  // 这里不支持,因为是在业务参数 $config 中
        ],
        // foo
        ['ref' => Foo::class] // 这种在一级参数就支持
    ],
],

@onanying onanying closed this as completed Sep 9, 2020
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

No branches or pull requests

2 participants