|
1
|
|
|
<?php |
|
2
|
|
|
namespace VideoGamesRecords\CoreBundle\Service\Team; |
|
3
|
|
|
|
|
4
|
|
|
use League\Flysystem\FilesystemException; |
|
|
|
|
|
|
5
|
|
|
use League\Flysystem\FilesystemOperator; |
|
|
|
|
|
|
6
|
|
|
use Symfony\Component\HttpFoundation\StreamedResponse; |
|
7
|
|
|
|
|
8
|
|
|
class AvatarManager |
|
9
|
|
|
{ |
|
10
|
|
|
private string $prefix = 'team/'; |
|
11
|
|
|
|
|
12
|
|
|
private array $extensions = array( |
|
13
|
|
|
'png' => 'image/png', |
|
14
|
|
|
'jpg' => 'image/jpeg' |
|
15
|
|
|
); |
|
16
|
|
|
|
|
17
|
|
|
private FilesystemOperator $vgrCoreStorage; |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
public function __construct(FilesystemOperator $vgrCoreStorage) |
|
21
|
|
|
{ |
|
22
|
|
|
$this->vgrCoreStorage = $vgrCoreStorage; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @throws FilesystemException |
|
27
|
|
|
*/ |
|
28
|
|
|
public function write(string $filename, string $contents): void |
|
29
|
|
|
{ |
|
30
|
|
|
$this->vgrCoreStorage->write($this->prefix . $filename, $contents); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @throws FilesystemException |
|
36
|
|
|
*/ |
|
37
|
|
|
public function read(string $filename): StreamedResponse |
|
38
|
|
|
{ |
|
39
|
|
|
$path = $this->prefix . $filename; |
|
40
|
|
|
if (!$this->vgrCoreStorage->fileExists($path)) { |
|
41
|
|
|
$path = $this->prefix . 'default.png'; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$stream = $this->vgrCoreStorage->readStream($path); |
|
45
|
|
|
return new StreamedResponse(function () use ($stream) { |
|
46
|
|
|
fpassthru($stream); |
|
47
|
|
|
exit(); |
|
|
|
|
|
|
48
|
|
|
}, 200, ['Content-Type' => $this->getMimeType($path)]); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
public function getAllowedMimeType(): array |
|
53
|
|
|
{ |
|
54
|
|
|
return array_values($this->extensions); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function getExtension($mimeType): string |
|
58
|
|
|
{ |
|
59
|
|
|
$types = array_flip($this->extensions); |
|
60
|
|
|
return $types[$mimeType] ?? 'png'; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
private function getMimeType(string $file): string |
|
64
|
|
|
{ |
|
65
|
|
|
$infos = pathinfo($file); |
|
66
|
|
|
return $this->extensions[$infos['extension']] ?? 'image/png'; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
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