调用未定义的方法GuzzleHttp \ Psr7 \ Uri :: composeComponents()

时间:2017-06-21 12:48:44

标签: php laravel amazon-s3 guzzle

我似乎无法在Laravel 5.4上使用简单的文件上传工作。我使用适当的S3环境变量正确配置了我的文件系统。当我使用此代码处理要上传的文件时:

$disk = Storage::disk('s3');
foreach ($request->allFiles() as $file) {
    $disk->putFileAs('file-requests', $file, $file->getClientOriginalName());
}

我收到此错误:

(1/1) FatalThrowableError
Call to undefined method GuzzleHttp\Psr7\Uri::composeComponents()
in UriResolver.php (line 102)
at UriResolver::resolve(object(Uri), object(Uri))
in RestSerializer.php (line 206)
at RestSerializer->buildEndpoint(object(Operation), array('Bucket' => 'myBucket', 'Key' => 'file-requests/test_2MB.dump', 'Body' => object(Stream), 'ACL' => 'private', 'ContentType' => 'text/plain', 'ContentLength' => 2097152, '@http' => array()), array('body' => object(Stream), 'headers' => array('x-amz-acl' => 'private', 'Content-Type' => 'text/plain', 'Content-Length' => 2097152)))
in RestSerializer.php (line 48)
at RestSerializer->__invoke(object(Command))
in Middleware.php (line 97)
at Middleware::Aws\{closure}(object(Command), null)
in Middleware.php (line 81)
at Middleware::Aws\{closure}(object(Command), null)
in S3Client.php (line 421)
at S3Client::Aws\S3\{closure}(object(Command), null)
in S3Client.php (line 444)
at S3Client::Aws\S3\{closure}(object(Command), null)
in S3Client.php (line 378)
at S3Client::Aws\S3\{closure}(object(Command), null)
in S3Client.php (line 397)
at S3Client::Aws\S3\{closure}(object(Command), null)
in Middleware.php (line 55)
at Middleware::Aws\{closure}(object(Command), null)
in SSECMiddleware.php (line 59)
at SSECMiddleware->__invoke(object(Command), null)
in IdempotencyTokenMiddleware.php (line 77)
at IdempotencyTokenMiddleware->__invoke(object(Command))
in AwsClientTrait.php (line 65)
at AwsClient->executeAsync(object(Command))
in ObjectUploader.php (line 90)
at ObjectUploader->promise()
in S3ClientTrait.php (line 44)
at S3Client->uploadAsync('myBucket', 'file-requests/test_2MB.dump', resource, 'private', array('params' => array('ContentType' => 'text/plain', 'ContentLength' => 2097152)))
in S3ClientTrait.php (line 29)
at S3Client->upload('myBucket', 'file-requests/test_2MB.dump', resource, 'private', array('params' => array('ContentType' => 'text/plain', 'ContentLength' => 2097152)))
in AwsS3Adapter.php (line 582)
at AwsS3Adapter->upload('file-requests/test_2MB.dump', resource, object(Config))
in AwsS3Adapter.php (line 367)
at AwsS3Adapter->writeStream('file-requests/test_2MB.dump', resource, object(Config))
in Filesystem.php (line 122)
at Filesystem->putStream('file-requests/test_2MB.dump', resource, object(Config))
in FilesystemAdapter.php (line 118)
at FilesystemAdapter->put('file-requests/test_2MB.dump', resource, array())
in FilesystemAdapter.php (line 152)
at FilesystemAdapter->putFileAs('file-requests/test_2MB.dump', object(UploadedFile), 'test_2MB.dump')
in FileRequestsController.php (line 373)
at FileRequestsController->upload(object(Request), object(FileRequest))
at call_user_func_array(array(object(FileRequestsController), 'upload'), array(object(Request), 'file_request' => object(FileRequest)))
in Controller.php (line 55)
at Controller->callAction('upload', array(object(Request), 'file_request' => object(FileRequest)))
in ControllerDispatcher.php (line 44)
at ControllerDispatcher->dispatch(object(Route), object(FileRequestsController), 'upload')
in Route.php (line 203)
at Route->runController()
in Route.php (line 160)
at Route->run()
in Router.php (line 574)
at Router->Illuminate\Routing\{closure}(object(Request))
in Pipeline.php (line 30)
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in BaseController.php (line 20)
at BaseController->App\Http\Controllers\{closure}(object(Request), object(Closure))
in Pipeline.php (line 131)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in LoginUsingOldPlm.php (line 39)
at LoginUsingOldPlm->handle(object(Request), object(Closure))
in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in SubstituteBindings.php (line 41)
at SubstituteBindings->handle(object(Request), object(Closure))
in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in Authenticate.php (line 43)
at Authenticate->handle(object(Request), object(Closure))
in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in VerifyCsrfToken.php (line 65)
at VerifyCsrfToken->handle(object(Request), object(Closure))
in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in ShareErrorsFromSession.php (line 49)
at ShareErrorsFromSession->handle(object(Request), object(Closure))
in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in StartSession.php (line 64)
at StartSession->handle(object(Request), object(Closure))
in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in AddQueuedCookiesToResponse.php (line 37)
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in EncryptCookies.php (line 59)
at EncryptCookies->handle(object(Request), object(Closure))
in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in Pipeline.php (line 102)
at Pipeline->then(object(Closure))
in Router.php (line 576)
at Router->runRouteWithinStack(object(Route), object(Request))
in Router.php (line 535)
at Router->dispatchToRoute(object(Request))
in Router.php (line 513)
at Router->dispatch(object(Request))
in Kernel.php (line 174)
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
in Pipeline.php (line 30)
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in TransformsRequest.php (line 30)
at TransformsRequest->handle(object(Request), object(Closure))
in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in TransformsRequest.php (line 30)
at TransformsRequest->handle(object(Request), object(Closure))
in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in ValidatePostSize.php (line 27)
at ValidatePostSize->handle(object(Request), object(Closure))
in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in CheckForMaintenanceMode.php (line 46)
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in Pipeline.php (line 102)
at Pipeline->then(object(Closure))
in Kernel.php (line 149)
at Kernel->sendRequestThroughRouter(object(Request))
in Kernel.php (line 116)
at Kernel->handle(object(Request))
in index.php (line 52)

但方法是IS定义的。也许我错过了一些东西,但我无法看到它。任何帮助表示赞赏。在UriResolver.php的第102行添加:

$_uri = new Uri();
var_dump(method_exists($_uri, 'composeComponents'));
exit;

在我新的Laravel安装中返回:

/home/vagrant/Code/test-aws/vendor/guzzlehttp/psr7/src/UriResolver.php:103:boolean true

在我的大型项目中,它说:

/home/vagrant/Code/plm/vendor/guzzlehttp/psr7/src/UriResolver.php:103:boolean false

即使确实存在。我相信真正的问题是什么会使类上的静态方法不存在或不可赎回。将方法移动到变量我能够完成我的文件上传到AWS,但这是各种错误:

$composeComponents = function ($scheme, $authority, $path, $query, $fragment) {
    $uri = '';

    // weak type checks to also accept null until we can add scalar type hints
    if ($scheme != '') {
        $uri .= $scheme . ':';
    }

    if ($authority != ''|| $scheme === 'file') {
        $uri .= '//' . $authority;
    }

    $uri .= $path;

    if ($query != '') {
        $uri .= '?' . $query;
    }

    if ($fragment != '') {
        $uri .= '#' . $fragment;
    }

    return $uri;
};

//$_uri = new Uri();
//var_dump($_uri);
//var_dump(method_exists($_uri, 'composeComponents'));
//exit;

//return new Uri(Uri::composeComponents(
return new Uri($composeComponents(
    $base->getScheme(),
    $targetAuthority,
    $targetPath,
    $targetQuery,
    $rel->getFragment()
));

2 个答案:

答案 0 :(得分:1)

这是一个自动加载问题。

我在Laravel中有一个较旧的网站,它有自己的自动加载功能。之所以发生这种情况,是因为中间件始终包含来自旧网站的文件,这会导致不正常的行为。

答案 1 :(得分:0)

尝试删除vendor/目录并重新安装所有Composer依赖项。

如果您使用"guzzlehttp/guzzle": "~6.2",则应该没问题。