UnauthenticatedResponseStrategy.php 1.08 KB
Newer Older
1
2
3
4
5
6
7
<?php


namespace App\Documentation\Strategies;

use ReflectionClass;
use Illuminate\Routing\Route;
Jacob Priddy's avatar
Jacob Priddy committed
8
9
use ReflectionFunctionAbstract;
use Knuckles\Scribe\Extracting\Strategies\Strategy;
10
11
12

class UnauthenticatedResponseStrategy extends Strategy
{
Jacob Priddy's avatar
Jacob Priddy committed
13
14
    public $stage = 'responses';

15
16
17
    /**
     * @inheritDoc
     */
Jacob Priddy's avatar
Jacob Priddy committed
18
    public function __invoke(Route $route, ReflectionClass $controller, ReflectionFunctionAbstract $method, array $routeRules, array $alreadyExtractedData = [])
19
    {
Jacob Priddy's avatar
Jacob Priddy committed
20
        if (!$alreadyExtractedData['metadata']['authenticated']) {
21
22
23
            return null;
        }

Jacob Priddy's avatar
Jacob Priddy committed
24
        $unauthenticated = [
25
26
27
28
                'content' => [
                    'message' => 'Unauthenticated',
                ],
                'status' => 401,
Jacob Priddy's avatar
Jacob Priddy committed
29
30
31
32
33
34
35
36
            ];

        if ($controller->getShortName() === 'DoorController') {
            return [$unauthenticated];
        }

        return [
            $unauthenticated,
37
38
39
40
41
42
43
            [
                'content' => [
                    'message' => 'Unauthorized',
                ],
                'status' => 403,
            ]
        ];
44
45
    }
}