1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Acquia\Hmac\Symfony; |
4
|
|
|
|
5
|
|
|
use Acquia\Hmac\ResponseSigner; |
6
|
|
|
use Laminas\Diactoros\ResponseFactory; |
7
|
|
|
use Laminas\Diactoros\ServerRequestFactory; |
8
|
|
|
use Laminas\Diactoros\StreamFactory; |
9
|
|
|
use Laminas\Diactoros\UploadedFileFactory; |
10
|
|
|
use Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory; |
|
|
|
|
11
|
|
|
use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory; |
12
|
|
|
use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory; |
13
|
|
|
use Symfony\Component\HttpKernel\Event\ResponseEvent; |
14
|
|
|
use Symfony\Component\HttpKernel\KernelEvents; |
15
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Signs the response from an HTTP HMAC-authenticated request. |
19
|
|
|
*/ |
20
|
3 |
|
class HmacResponseListener implements EventSubscriberInterface |
21
|
|
|
{ |
22
|
3 |
|
/** |
23
|
1 |
|
* @param \Symfony\Component\HttpKernel\Event\ResponseEvent $event |
24
|
|
|
*/ |
25
|
|
|
public function onKernelResponse(ResponseEvent $event) |
26
|
2 |
|
{ |
27
|
2 |
|
if (!$event->isMasterRequest()) { |
28
|
|
|
return; |
29
|
2 |
|
} |
30
|
1 |
|
|
31
|
1 |
|
$request = $event->getRequest(); |
32
|
|
|
$response = $event->getResponse(); |
33
|
1 |
|
|
34
|
1 |
|
if ($request->attributes->has('hmac.key')) { |
35
|
|
|
if (class_exists(DiactorosFactory::class)) { |
36
|
1 |
|
$httpMessageFactory = new DiactorosFactory(); |
37
|
1 |
|
} else { |
38
|
|
|
$httpMessageFactory = new PsrHttpFactory(new ServerRequestFactory(), new StreamFactory(), new UploadedFileFactory(), new ResponseFactory()); |
39
|
1 |
|
} |
40
|
|
|
|
41
|
2 |
|
$foundationFactory = new HttpFoundationFactory(); |
42
|
|
|
|
43
|
|
|
$psr7Request = $httpMessageFactory->createRequest($request); |
44
|
|
|
$psr7Response = $httpMessageFactory->createResponse($response); |
45
|
|
|
|
46
|
1 |
|
$signer = new ResponseSigner($request->attributes->get('hmac.key'), $psr7Request); |
47
|
|
|
$signedResponse = $signer->signResponse($psr7Response); |
48
|
1 |
|
|
49
|
|
|
$event->setResponse($foundationFactory->createResponse($signedResponse)); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritdoc} |
55
|
|
|
*/ |
56
|
|
|
public static function getSubscribedEvents() |
57
|
|
|
{ |
58
|
|
|
return [KernelEvents::RESPONSE => 'onKernelResponse']; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths