1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Controller; |
4
|
|
|
|
5
|
|
|
use App\DeferredResponseFactory; |
|
|
|
|
6
|
|
|
use App\Entity\User; |
7
|
|
|
use App\Repository\UserRepository; |
8
|
|
|
use Cycle\ORM\ORMInterface; |
9
|
|
|
use Psr\Http\Message\ResponseInterface; |
10
|
|
|
use Psr\Http\Message\ServerRequestInterface as Request; |
11
|
|
|
use Yiisoft\Data\Reader\Sort; |
12
|
|
|
use Yiisoft\Yii\Web\ResponseFactory; |
|
|
|
|
13
|
|
|
|
14
|
|
|
class ApiUserController |
15
|
|
|
{ |
16
|
|
|
private ResponseFactory $responseFactory; |
17
|
|
|
|
18
|
|
|
public function __construct(ResponseFactory $responseFactory) |
19
|
|
|
{ |
20
|
|
|
$this->responseFactory = $responseFactory; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function index(ORMInterface $orm): ResponseInterface |
24
|
|
|
{ |
25
|
|
|
/** @var UserRepository $userRepo */ |
26
|
|
|
$userRepo = $orm->getRepository(User::class); |
27
|
|
|
|
28
|
|
|
$dataReader = $userRepo->findAll()->withSort((new Sort([]))->withOrderString('login')); |
29
|
|
|
$users = $dataReader->read(); |
30
|
|
|
|
31
|
|
|
$items = []; |
32
|
|
|
foreach ($users as $user) { |
33
|
|
|
$items[] = ['login' => $user->getLogin(), 'created_at' => $user->getCreatedAt()->format('H:i:s d.m.Y')]; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
return $this->responseFactory->createResponse(200, '', $items); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function profile(Request $request, ORMInterface $orm): ResponseInterface |
40
|
|
|
{ |
41
|
|
|
/** @var UserRepository $userRepository */ |
42
|
|
|
$userRepository = $orm->getRepository(User::class); |
43
|
|
|
$login = $request->getAttribute('login', null); |
44
|
|
|
|
45
|
|
|
/** @var User $user */ |
46
|
|
|
$user = $userRepository->findByLogin($login); |
47
|
|
|
if ($user === null) { |
48
|
|
|
return $this->responseFactory->createResponse(404, '', 'Page not found')->withStatus(404); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return $this->responseFactory->createResponse( |
52
|
|
|
200, |
53
|
|
|
'', |
54
|
|
|
['login' => $user->getLogin(), 'created_at' => $user->getCreatedAt()->format('H:i:s d.m.Y')] |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
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