|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Spiral\Broadcasting\Middleware; |
|
6
|
|
|
|
|
7
|
|
|
use Psr\Http\Message\ResponseFactoryInterface; |
|
8
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
9
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
10
|
|
|
use Psr\Http\Server\MiddlewareInterface; |
|
11
|
|
|
use Psr\Http\Server\RequestHandlerInterface; |
|
12
|
|
|
use Spiral\Broadcasting\BroadcastInterface; |
|
13
|
|
|
use Spiral\Broadcasting\Config\BroadcastConfig; |
|
14
|
|
|
use Spiral\Broadcasting\GuardInterface; |
|
15
|
|
|
|
|
16
|
|
|
final class AuthorizationMiddleware implements MiddlewareInterface |
|
17
|
|
|
{ |
|
18
|
|
|
private ResponseFactoryInterface $responseFactory; |
|
19
|
|
|
private BroadcastInterface $broadcast; |
|
20
|
|
|
private ?string $authorizationPath; |
|
21
|
|
|
|
|
22
|
|
|
public function __construct( |
|
23
|
|
|
BroadcastInterface $broadcast, |
|
24
|
|
|
ResponseFactoryInterface $responseFactory, |
|
25
|
|
|
?string $authorizationPath = null |
|
26
|
|
|
) { |
|
27
|
|
|
$this->responseFactory = $responseFactory; |
|
28
|
|
|
$this->broadcast = $broadcast; |
|
29
|
|
|
$this->authorizationPath = $authorizationPath; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function process( |
|
33
|
|
|
ServerRequestInterface $request, |
|
34
|
|
|
RequestHandlerInterface $handler |
|
35
|
|
|
): ResponseInterface { |
|
36
|
|
|
if ($request->getUri()->getPath() !== $this->authorizationPath) { |
|
37
|
|
|
return $handler->handle($request); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
if ( |
|
41
|
|
|
!$this->broadcast instanceof GuardInterface |
|
42
|
|
|
|| $this->broadcast->authorize($request) |
|
|
|
|
|
|
43
|
|
|
) { |
|
44
|
|
|
return $this->responseFactory->createResponse(200); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
return $this->responseFactory->createResponse(403); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.