1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace VideoGamesRecords\CoreBundle\Controller; |
4
|
|
|
|
5
|
|
|
use League\Flysystem\FilesystemException; |
6
|
|
|
use League\Flysystem\FilesystemOperator; |
7
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache; |
|
|
|
|
8
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
10
|
|
|
use Symfony\Component\HttpFoundation\StreamedResponse; |
11
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
12
|
|
|
use VideoGamesRecords\CoreBundle\Entity\Game; |
13
|
|
|
use VideoGamesRecords\CoreBundle\Repository\GameRepository; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class GameController |
17
|
|
|
* @Route("/game") |
18
|
|
|
*/ |
19
|
|
|
class GameController extends AbstractController |
20
|
|
|
{ |
21
|
|
|
private GameRepository $gameRepository; |
22
|
|
|
private FilesystemOperator $appStorage; |
23
|
|
|
|
24
|
|
|
private string $prefix = 'game/'; |
25
|
|
|
|
26
|
|
|
public function __construct(GameRepository $gameRepository, FilesystemOperator $appStorage) |
27
|
|
|
{ |
28
|
|
|
$this->gameRepository = $gameRepository; |
29
|
|
|
$this->appStorage = $appStorage; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param Request $request |
34
|
|
|
* @return mixed |
35
|
|
|
*/ |
36
|
|
|
public function listByLetter(Request $request): mixed |
37
|
|
|
{ |
38
|
|
|
$letter = $request->query->get('letter', '0'); |
39
|
|
|
$locale = $request->getLocale(); |
40
|
|
|
return $this->gameRepository |
41
|
|
|
->findWithLetter($letter, $locale) |
42
|
|
|
->getResult(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @Route(path="/{id}/picture", requirements={"id": "[1-9]\d*"}, name="vgr_core_game_picture", methods={"GET"}) |
47
|
|
|
* @Cache(expires="+30 days") |
48
|
|
|
* @param Game $game |
49
|
|
|
* @return StreamedResponse |
50
|
|
|
* @throws FilesystemException |
51
|
|
|
*/ |
52
|
|
|
public function pictureAction(Game $game): StreamedResponse |
53
|
|
|
{ |
54
|
|
|
$path = $this->prefix . $game->getPicture(); |
55
|
|
|
if (!$this->appStorage->fileExists($path)) { |
56
|
|
|
$path = $this->prefix . 'default.png'; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$stream = $this->appStorage->readStream($path); |
60
|
|
|
return new StreamedResponse(function() use ($stream) { |
61
|
|
|
fpassthru($stream); |
62
|
|
|
}, 200, ['Content-Type' => 'image/png']); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
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