GetAuthenticationStrategy.php 1.14 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 GetAuthenticationStrategy extends Strategy
{
Jacob Priddy's avatar
Jacob Priddy committed
13
14
    public $stage = 'queryParameters';

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
20
21
22
23
    {
        if (!in_array('GET', $route->methods(), true)) {
            return null;
        }

Jacob Priddy's avatar
Jacob Priddy committed
24
        if (!$alreadyExtractedData['metadata']['authenticated']) {
25
26
27
28
29
30
31
32
33
34
            return null;
        }

        $token = 'token_string_admin';
        if ($controller->getShortName() === 'MeController') {
            $token = 'token_string_engr';
        }

        return [
            'api_token' => [
Jacob Priddy's avatar
Jacob Priddy committed
35
                'name' => 'api_token',
36
37
38
39
40
41
42
43
                'type' => 'string',
                'description' => 'The api authentication token to use. Can be used in place of a bearer token.',
                'required' => false,
                'value' => $token,
            ],
        ];
    }
}