Skip to content

Commit 5ee9dee

Browse files
authored
Merge pull request #3 from onliner/update-to-3x
Support new processing options for ImgProxy 3
2 parents 84bd724 + 7317b5c commit 5ee9dee

62 files changed

Lines changed: 1089 additions & 330 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
strategy:
99
matrix:
1010
os: [ubuntu-latest]
11-
php: ['7.2', '7.3', '7.4', '8.0']
11+
php: ['8.0', '8.1', '8.2']
1212
name: PHP ${{ matrix.php }} Test on ${{ matrix.os }}
1313
steps:
1414
- name: Checkout

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"keywords": ["imgproxy", "imageproxy", "image", "resize"],
66
"license": "MIT",
77
"require": {
8-
"php": "^7.2 || ^8.0"
8+
"php": "^8.0"
99
},
1010
"require-dev": {
1111
"phpunit/phpunit": "^8.5.8|^9.3.3",

src/Options/AbstractOption.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Onliner\ImgProxy\Options;
6+
7+
abstract class AbstractOption
8+
{
9+
/**
10+
* @return string
11+
*/
12+
abstract public function name(): string;
13+
14+
/**
15+
* @return array<mixed>
16+
*/
17+
abstract public function data(): array;
18+
19+
/**
20+
* @return string
21+
*/
22+
public function value(): string
23+
{
24+
$data = $this->data();
25+
26+
array_unshift($data, $this->name());
27+
28+
// Remove empty options from end.
29+
return rtrim(implode(':', $data), ':');
30+
}
31+
32+
/**
33+
* @return string
34+
*/
35+
public function __toString(): string
36+
{
37+
return $this->value();
38+
}
39+
}

src/Options/AutoRotate.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44

55
namespace Onliner\ImgProxy\Options;
66

7-
final class AutoRotate extends Option
7+
final class AutoRotate extends AbstractOption
88
{
9-
/**
10-
* @var bool
11-
*/
12-
private $rotate;
9+
private bool $rotate;
1310

1411
public function __construct(bool $rotate = true)
1512
{

src/Options/Background.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66

77
use Onliner\ImgProxy\Support\Color;
88

9-
final class Background extends Option
9+
final class Background extends AbstractOption
1010
{
11-
/**
12-
* @var Color
13-
*/
14-
private $color;
11+
private Color $color;
1512

1613
public function __construct(string $color)
1714
{

src/Options/Blur.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66

77
use InvalidArgumentException;
88

9-
final class Blur extends Option
9+
final class Blur extends AbstractOption
1010
{
11-
/**
12-
* @var float
13-
*/
14-
private $sigma;
11+
private float $sigma;
1512

1613
public function __construct(float $sigma)
1714
{

src/Options/CacheBuster.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66

77
use InvalidArgumentException;
88

9-
final class CacheBuster extends Option
9+
final class CacheBuster extends AbstractOption
1010
{
11-
/**
12-
* @var string
13-
*/
14-
private $value;
11+
private string $value;
1512

1613
public function __construct(string $value)
1714
{

src/Options/Crop.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,13 @@
44

55
namespace Onliner\ImgProxy\Options;
66

7-
final class Crop extends Option
7+
final class Crop extends AbstractOption
88
{
9-
/**
10-
* @var Width
11-
*/
12-
private $width;
13-
/**
14-
* @var Height
15-
*/
16-
private $height;
17-
/**
18-
* @var Gravity|null
19-
*/
20-
private $gravity;
9+
private Width $width;
10+
private Height $height;
11+
private ?Gravity $gravity = null;
2112

22-
public function __construct(int $width, int $height, string $gravity = null)
13+
public function __construct(int $width, int $height, ?string $gravity = null)
2314
{
2415
$this->width = new Width($width);
2516
$this->height = new Height($height);

src/Options/Dpr.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66

77
use InvalidArgumentException;
88

9-
final class Dpr extends Option
9+
final class Dpr extends AbstractOption
1010
{
11-
/**
12-
* @var int
13-
*/
14-
private $dpr;
11+
private int $dpr;
1512

1613
public function __construct(int $dpr)
1714
{

src/Options/EnforceThumbnail.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Onliner\ImgProxy\Options;
6+
7+
final class EnforceThumbnail extends AbstractOption
8+
{
9+
private ?string $format;
10+
11+
public function __construct(?string $format = null)
12+
{
13+
$this->format = $format;
14+
}
15+
16+
/**
17+
* @inheritDoc
18+
*/
19+
public function name(): string
20+
{
21+
return 'eth';
22+
}
23+
24+
/**
25+
* @inheritDoc
26+
*/
27+
public function data(): array
28+
{
29+
return [
30+
$this->format ?: true,
31+
];
32+
}
33+
}

0 commit comments

Comments
 (0)