Skip to content

Commit 424f645

Browse files
committed
run pint
1 parent b1d4199 commit 424f645

18 files changed

+56
-56
lines changed

config/image-proxy.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
return [
44
'route_prefix' => env('IMAGE_PROXY_ROUTE_PREFIX', 'img'),
55
'route_names' => [
6-
'image.proxy.short' => env('IMAGE_PROXY_ROUTE_SHORT', 'image.proxy.short'),
6+
'image.proxy.short' => env('IMAGE_PROXY_ROUTE_SHORT', 'image.proxy.short'),
77
'image.proxy.filename' => env('IMAGE_PROXY_ROUTE_FILENAME', 'image.proxy.filename'),
88
],
99
'route_middleware' => [],
1010
'disks' => [
1111
'source' => env('IMAGE_PROXY_DISK_SOURCE', 'local'),
12-
'cache' => env('IMAGE_PROXY_DISK_CACHE', 'local'),
12+
'cache' => env('IMAGE_PROXY_DISK_CACHE', 'local'),
1313
],
1414
'encryptor' => Bst27\ImageProxy\Services\OpenSslPayloadEncryptor::class,
1515
'token_encoder' => Bst27\ImageProxy\Services\Base64UrlTokenEncoder::class,
1616
'manipulation_strategy' => [
1717
'default' => [
18-
'class' => \Bst27\ImageProxy\Services\ImageManipulator\DefaultManipulator::class,
18+
'class' => \Bst27\ImageProxy\Services\ImageManipulator\DefaultManipulator::class,
1919
'params' => [],
2020
],
2121
],

routes/web.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
use Illuminate\Support\Facades\Route;
55

66
$prefix = config('image-proxy.route_prefix');
7-
$names = config('image-proxy.route_names');
7+
$names = config('image-proxy.route_names');
88
$middleware = config('image-proxy.route_middleware');
99

1010
Route::group([
11-
'prefix' => $prefix,
11+
'prefix' => $prefix,
1212
'middleware' => $middleware,
13-
], function() use ($names) {
13+
], function () use ($names) {
1414
Route::get('{token}.{ext}', [ImageProxyController::class, 'serveShort'])
1515
->where('token', '[A-Za-z0-9\-_]+')
1616
->where('ext', '[A-Za-z0-9]+')

src/Contracts/ImageManipulator.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ interface ImageManipulator
77
/**
88
* This function has to return the content of the manipulated file as string.
99
* It is given the original file content and any additional parameters if available.
10-
*
11-
* @param string $fileContent
12-
* @param array $params
13-
* @return string
1410
*/
1511
public function manipulate(string $fileContent, array $params): string;
1612
}

src/Contracts/PayloadEncryptor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
interface PayloadEncryptor
66
{
77
public function encrypt(string $payload): string;
8+
89
public function decrypt(string $cipher): string;
910
}

src/Contracts/TokenEncoder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
interface TokenEncoder
66
{
77
public function encode(string $cipher): string;
8+
89
public function decode(string $token): string;
910
}

src/Http/Controllers/ImageProxyController.php

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ public function serveFilename(string $token, string $filename): Response
3838

3939
private function decryptPayload(string $token): array
4040
{
41-
$encoder = app(TokenEncoder::class);
42-
$cipher = $encoder->decode($token);
41+
$encoder = app(TokenEncoder::class);
42+
$cipher = $encoder->decode($token);
4343
$encryptor = app(PayloadEncryptor::class);
44-
$json = $encryptor->decrypt($cipher);
44+
$json = $encryptor->decrypt($cipher);
4545

4646
$data = json_decode($json, true);
4747
if (! $data || ! isset($data['path'], $data['v'])) {
@@ -54,11 +54,11 @@ private function decryptPayload(string $token): array
5454
private function processAndDeliver(array $data): Response
5555
{
5656
$sourceDisk = Storage::disk(config('image-proxy.disks.source'));
57-
$cacheDisk = Storage::disk(config('image-proxy.disks.cache'));
57+
$cacheDisk = Storage::disk(config('image-proxy.disks.cache'));
5858

5959
$sourcePath = $data['path'];
6060

61-
if (!$sourceDisk->exists($sourcePath)) {
61+
if (! $sourceDisk->exists($sourcePath)) {
6262
abort(404);
6363
}
6464

@@ -69,23 +69,23 @@ private function processAndDeliver(array $data): Response
6969
}
7070

7171
$strategyKey = $data['strategy'];
72-
$strategies = config('image-proxy.manipulation_strategy');
72+
$strategies = config('image-proxy.manipulation_strategy');
7373

7474
if (! isset($strategies[$strategyKey])) {
7575
abort(500, "Unknown image-proxy strategy: {$strategyKey}");
7676
}
7777

78-
$conf = $strategies[$strategyKey];
79-
$class = $conf['class'];
80-
$default = $conf['params'] ?? [];
81-
$mergeParams = $data['mergeParams'] ?? [];
82-
$params = array_merge($default, $mergeParams);
78+
$conf = $strategies[$strategyKey];
79+
$class = $conf['class'];
80+
$default = $conf['params'] ?? [];
81+
$mergeParams = $data['mergeParams'] ?? [];
82+
$params = array_merge($default, $mergeParams);
8383

84-
$ext = pathinfo($sourcePath, PATHINFO_EXTENSION);
85-
$cacheHash = $fileHash . '-' . md5(json_encode($params));
86-
$cacheKey = $cacheHash . '.' . $ext;
84+
$ext = pathinfo($sourcePath, PATHINFO_EXTENSION);
85+
$cacheHash = $fileHash.'-'.md5(json_encode($params));
86+
$cacheKey = $cacheHash.'.'.$ext;
8787

88-
if (!$cacheDisk->exists($cacheKey)) {
88+
if (! $cacheDisk->exists($cacheKey)) {
8989
/** @var ImageManipulator $manipulator */
9090
$manipulator = app($class);
9191
$fileContent = $manipulator->manipulate($fileContent, $params);
@@ -94,10 +94,11 @@ private function processAndDeliver(array $data): Response
9494
}
9595

9696
$stream = $cacheDisk->readStream($cacheKey);
97-
return new StreamedResponse(function() use ($stream) {
97+
98+
return new StreamedResponse(function () use ($stream) {
9899
fpassthru($stream);
99100
}, 200, [
100-
'Content-Type' => $cacheDisk->mimeType($cacheKey),
101+
'Content-Type' => $cacheDisk->mimeType($cacheKey),
101102
'Cache-Control' => 'public, max-age=31536000, immutable',
102103
]);
103104
}

src/ImageProxyServiceProvider.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Bst27\ImageProxy\Contracts\PayloadEncryptor;
66
use Bst27\ImageProxy\Contracts\TokenEncoder;
7-
use Illuminate\Support\Facades\Route;
87
use Illuminate\Support\ServiceProvider;
98

109
class ImageProxyServiceProvider extends ServiceProvider

src/Services/Base64UrlTokenEncoder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace Bst27\ImageProxy\Services;
34

45
use Bst27\ImageProxy\Contracts\TokenEncoder;
@@ -13,6 +14,7 @@ public function encode(string $cipher): string
1314
public function decode(string $token): string
1415
{
1516
$b64 = strtr($token, '-_', '+/');
17+
1618
return (string) base64_decode($b64);
1719
}
1820
}

src/Services/ImageManipulator/DefaultManipulator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class DefaultManipulator implements ImageManipulator
99
{
1010
public function manipulate(string $fileContent, array $params): string
1111
{
12-
$tmpFile = tempnam(sys_get_temp_dir(), 'img');
12+
$tmpFile = tempnam(sys_get_temp_dir(), 'img');
1313
file_put_contents($tmpFile, $fileContent);
1414

1515
try {

src/Services/OpenSslPayloadEncryptor.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<?php
2+
23
namespace Bst27\ImageProxy\Services;
34

45
use Bst27\ImageProxy\Contracts\PayloadEncryptor;
56

67
class OpenSslPayloadEncryptor implements PayloadEncryptor
78
{
89
private const HASH_ALGORITHM = 'sha256';
10+
911
private const CIPHER_ALGORITHM = 'AES-256-ECB';
1012

1113
public function encrypt(string $payload): string

0 commit comments

Comments
 (0)