|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace App\User\Controller; |
|
6
|
|
|
|
|
7
|
|
|
use App\User\UserRepository; |
|
8
|
|
|
use Yiisoft\Data\Paginator\PageToken; |
|
|
|
|
|
|
9
|
|
|
use Psr\Http\Message\ResponseFactoryInterface; |
|
|
|
|
|
|
10
|
|
|
use Psr\Http\Message\ResponseInterface as Response; |
|
|
|
|
|
|
11
|
|
|
use Yiisoft\Data\Paginator\OffsetPaginator; |
|
|
|
|
|
|
12
|
|
|
use Yiisoft\Data\Reader\Sort; |
|
|
|
|
|
|
13
|
|
|
use Yiisoft\Input\Http\Attribute\Parameter\Body; |
|
|
|
|
|
|
14
|
|
|
use Yiisoft\Input\Http\Attribute\Parameter\Query; |
|
|
|
|
|
|
15
|
|
|
use Yiisoft\Router\HydratorAttribute\RouteArgument; |
|
|
|
|
|
|
16
|
|
|
use Yiisoft\Yii\View\Renderer\ViewRenderer; |
|
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
final class UserController |
|
19
|
|
|
{ |
|
20
|
|
|
public function __construct(private ViewRenderer $viewRenderer) |
|
21
|
|
|
{ |
|
22
|
|
|
$this->viewRenderer = $viewRenderer->withControllerName('user'); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function index( |
|
26
|
|
|
UserRepository $userRepository, |
|
27
|
|
|
#[Body] ?array $body, |
|
28
|
|
|
#[Query('sort')] ?string $sortOrder = null, |
|
29
|
|
|
#[RouteArgument('page')] int $page = 1, |
|
30
|
|
|
#[RouteArgument('pagesize')] int $pageSize = null, |
|
31
|
|
|
): Response { |
|
32
|
|
|
$dataReader = $userRepository |
|
33
|
|
|
->findAll() |
|
34
|
|
|
->withSort(Sort::only(['id', 'login']) |
|
35
|
|
|
->withOrderString($sortOrder ?? 'id')); |
|
36
|
|
|
|
|
37
|
|
|
if ($pageSize === null) { |
|
38
|
|
|
$pageSize = (int) ($body['pageSize'] ?? OffSetPaginator::DEFAULT_PAGE_SIZE); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
$paginator = (new OffsetPaginator($dataReader)); |
|
42
|
|
|
$paginator = $paginator->withToken(PageToken::next((string) $page))->withPageSize($pageSize); |
|
43
|
|
|
|
|
44
|
|
|
return $this->viewRenderer->render('index', ['paginator' => $paginator]); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function profile( |
|
48
|
|
|
#[RouteArgument('login')] string $login, |
|
49
|
|
|
ResponseFactoryInterface $responseFactory, |
|
50
|
|
|
UserRepository $userRepository |
|
51
|
|
|
): Response { |
|
52
|
|
|
$item = $userRepository->findByLogin($login); |
|
53
|
|
|
|
|
54
|
|
|
if ($item === null) { |
|
55
|
|
|
return $responseFactory->createResponse(404); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return $this->viewRenderer->render('profile', ['item' => $item]); |
|
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