1111 */
1212class PresignUrlMiddleware
1313{
14- private $ client ;
14+ private \ WeakReference $ client ;
1515 private $ endpointProvider ;
1616 private $ nextHandler ;
1717 /** @var array names of operations that require presign url */
@@ -32,7 +32,7 @@ public function __construct(
3232 callable $ nextHandler
3333 ) {
3434 $ this ->endpointProvider = $ endpointProvider ;
35- $ this ->client = $ client ;
35+ $ this ->client = \WeakReference:: create ( $ client) ;
3636 $ this ->nextHandler = $ nextHandler ;
3737 $ this ->commandPool = $ options ['operations ' ];
3838 $ this ->serviceName = $ options ['service ' ];
@@ -61,15 +61,16 @@ public function __invoke(CommandInterface $cmd, ?RequestInterface $request = nul
6161 if (in_array ($ cmd ->getName (), $ this ->commandPool )
6262 && (!isset ($ cmd ['__skip ' . $ cmd ->getName ()]))
6363 ) {
64- $ cmd ['DestinationRegion ' ] = $ this ->client ->getRegion ();
64+ $ client = $ this ->client ->get ();
65+ $ cmd ['DestinationRegion ' ] = $ client ->getRegion ();
6566 if (!empty ($ cmd ['SourceRegion ' ]) && !empty ($ cmd [$ this ->presignParam ])) {
6667 goto nexthandler;
6768 }
6869 if (!$ this ->requireDifferentRegion
6970 || (!empty ($ cmd ['SourceRegion ' ])
7071 && $ cmd ['SourceRegion ' ] !== $ cmd ['DestinationRegion ' ])
7172 ) {
72- $ cmd [$ this ->presignParam ] = $ this ->createPresignedUrl ($ this -> client , $ cmd );
73+ $ cmd [$ this ->presignParam ] = $ this ->createPresignedUrl ($ client , $ cmd );
7374 }
7475 }
7576 nexthandler:
@@ -91,7 +92,7 @@ private function createPresignedUrl(
9192 // Create the new endpoint for the target endpoint.
9293 if ($ this ->endpointProvider instanceof \Aws \EndpointV2 \EndpointProviderV2) {
9394 $ providerArgs = array_merge (
94- $ this ->client ->getEndpointProviderArgs (),
95+ $ this ->client ->get ()-> getEndpointProviderArgs (),
9596 ['Region ' => $ cmd ['SourceRegion ' ]]
9697 );
9798 $ endpoint = $ this ->endpointProvider ->resolveEndpoint ($ providerArgs )->getUrl ();
0 commit comments