PaginationStrategy.php 958 Bytes
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 PaginationStrategy 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 (strpos($method->getDocComment(), "@paginated\n") === false) {
25
26
27
28
29
            return null;
        }

        return [
            'page' => [
Jacob Priddy's avatar
Jacob Priddy committed
30
                'name' => 'page',
31
32
33
34
35
36
37
38
                'type' => 'integer',
                'description' => 'The page of paginated data to get.',
                'required' => false,
                'value' => 1,
            ],
        ];
    }
}