mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-27 10:16:47 +00:00
41 lines
963 B
PHP
41 lines
963 B
PHP
|
<?php
|
||
|
|
||
|
namespace App\Util\HttpSignatures;
|
||
|
|
||
|
use GuzzleHttp\HandlerStack;
|
||
|
use GuzzleHttp\Psr7\Request;
|
||
|
use App\Util\HttpSignatures\Context;
|
||
|
|
||
|
class GuzzleHttpSignatures
|
||
|
{
|
||
|
/**
|
||
|
* @param Context $context
|
||
|
* @return HandlerStack
|
||
|
*/
|
||
|
public static function defaultHandlerFromContext(Context $context)
|
||
|
{
|
||
|
$stack = HandlerStack::create();
|
||
|
$stack->push(self::middlewareFromContext($context));
|
||
|
|
||
|
return $stack;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @param Context $context
|
||
|
* @return \Closure
|
||
|
*/
|
||
|
public static function middlewareFromContext(Context $context)
|
||
|
{
|
||
|
return function (callable $handler) use ($context)
|
||
|
{
|
||
|
return function (
|
||
|
Request $request,
|
||
|
array $options
|
||
|
) use ($handler, $context)
|
||
|
{
|
||
|
$request = $context->signer()->sign($request);
|
||
|
return $handler($request, $options);
|
||
|
};
|
||
|
};
|
||
|
}
|
||
|
}
|