-
Notifications
You must be signed in to change notification settings - Fork 380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Filters] [Config] [DI] Add Filter configuration class as public service #1098
Changes from 23 commits
6b41c3b
11c0c12
6a8cff3
add533f
95db82b
d907670
e213124
851a38b
27c8794
5c4d68f
e306612
db0a518
d6c599f
6906000
4ea4acc
ebc5744
02e4022
c4923d0
c564a62
9971029
36d7843
91bfe94
9df4d4b
be890e3
8458b37
6613b61
cdab3b8
f8cdfb7
2a397ae
f1ed641
0624a2a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,7 +60,7 @@ public function locate(string $path): string | |
*/ | ||
protected function generateAbsolutePath(string $root, string $path): ?string | ||
{ | ||
if (false !== $absolute = realpath($root.DIRECTORY_SEPARATOR.$path)) { | ||
if (false !== $absolute = realpath($root.\DIRECTORY_SEPARATOR.$path)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why the backslashes here? |
||
return $absolute; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the `liip/LiipImagineBundle` project. | ||
* | ||
* (c) /~https://github.com/liip/LiipImagineBundle/graphs/contributors | ||
* | ||
* For the full copyright and license information, please view the LICENSE.md | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Liip\ImagineBundle\Config\Filter\Argument; | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
final class Point | ||
{ | ||
/** | ||
* @var int | ||
*/ | ||
private $x; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $y; | ||
|
||
public function __construct(int $x = null, int $y = null) | ||
{ | ||
$this->x = $x; | ||
$this->y = $y; | ||
} | ||
|
||
public function getX(): ?int | ||
{ | ||
return $this->x; | ||
} | ||
|
||
public function getY(): ?int | ||
{ | ||
return $this->y; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the `liip/LiipImagineBundle` project. | ||
* | ||
* (c) /~https://github.com/liip/LiipImagineBundle/graphs/contributors | ||
* | ||
* For the full copyright and license information, please view the LICENSE.md | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Liip\ImagineBundle\Config\Filter\Argument; | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
final class Size | ||
{ | ||
/** | ||
* @var int | ||
*/ | ||
private $width; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $height; | ||
|
||
/** | ||
* To allow keeping aspect ratio, it is allowed to only specify one of width or height. | ||
* It is however not allowed to specify neither dimension. | ||
*/ | ||
public function __construct(int $width = null, int $height = null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does size without width and height has any business value? Same for point. It looks like incomplete/invalid object. If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Koc there are cases, when one of the dimensions could be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets add a phpdoc to this method? "To allow keeping aspect ratio, it is allowed to only specify one of width or height. It is however not allowed to specify neither dimension." |
||
{ | ||
$this->width = $width; | ||
$this->height = $height; | ||
} | ||
|
||
public function getWidth(): ?int | ||
{ | ||
return $this->width; | ||
} | ||
|
||
public function getHeight(): ?int | ||
{ | ||
return $this->height; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the `liip/LiipImagineBundle` project. | ||
* | ||
* (c) /~https://github.com/liip/LiipImagineBundle/graphs/contributors | ||
* | ||
* For the full copyright and license information, please view the LICENSE.md | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Liip\ImagineBundle\Config\Filter\Type; | ||
|
||
use Liip\ImagineBundle\Config\FilterInterface; | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
final class AutoRotate extends FilterAbstract implements FilterInterface | ||
{ | ||
const NAME = 'auto_rotate'; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the `liip/LiipImagineBundle` project. | ||
* | ||
* (c) /~https://github.com/liip/LiipImagineBundle/graphs/contributors | ||
* | ||
* For the full copyright and license information, please view the LICENSE.md | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Liip\ImagineBundle\Config\Filter\Type; | ||
|
||
use Liip\ImagineBundle\Config\Filter\Argument\Size; | ||
use Liip\ImagineBundle\Config\FilterInterface; | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
final class Background extends FilterAbstract implements FilterInterface | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
{ | ||
const NAME = 'background'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $color; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $transparency; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $position; | ||
|
||
/** | ||
* @var Size | ||
*/ | ||
private $size; | ||
|
||
/** | ||
* @param string|null $color background color HEX value | ||
* @param string|null $transparency possible values 0..100 | ||
* @param string|null $position position of the input image on the newly created background image. Valid values: topleft, top, topright, left, center, right, bottomleft, bottom, and bottomright | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can use value objects/enum here also. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Koc for all parameters or for specific one ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i would not use value objects here. if the imagine library would use them, we should use them here too, but as they don't i feel like its a bit too much. |
||
* @param Size $size | ||
*/ | ||
public function __construct( | ||
string $color = null, | ||
string $transparency = null, | ||
string $position = null, | ||
Size $size | ||
) { | ||
$this->color = $color; | ||
$this->transparency = $transparency; | ||
$this->position = $position; | ||
$this->size = $size; | ||
} | ||
|
||
public function getColor(): string | ||
{ | ||
return $this->color; | ||
} | ||
|
||
public function getTransparency(): string | ||
{ | ||
return $this->transparency; | ||
} | ||
|
||
public function getPosition(): ?string | ||
{ | ||
return $this->position; | ||
} | ||
|
||
public function getSize(): Size | ||
{ | ||
return $this->size; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the `liip/LiipImagineBundle` project. | ||
* | ||
* (c) /~https://github.com/liip/LiipImagineBundle/graphs/contributors | ||
* | ||
* For the full copyright and license information, please view the LICENSE.md | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Liip\ImagineBundle\Config\Filter\Type; | ||
|
||
use Liip\ImagineBundle\Config\Filter\Argument\Point; | ||
use Liip\ImagineBundle\Config\Filter\Argument\Size; | ||
use Liip\ImagineBundle\Config\FilterInterface; | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
final class Crop extends FilterAbstract implements FilterInterface | ||
{ | ||
const NAME = 'crop'; | ||
|
||
/** | ||
* @var Point | ||
*/ | ||
private $startPoint; | ||
|
||
/** | ||
* @var Size | ||
*/ | ||
private $size; | ||
|
||
public function __construct(Point $startPoint, Size $size) | ||
{ | ||
$this->startPoint = $startPoint; | ||
$this->size = $size; | ||
} | ||
|
||
public function getStartPoint(): Point | ||
{ | ||
return $this->startPoint; | ||
} | ||
|
||
public function getSize(): Size | ||
{ | ||
return $this->size; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the `liip/LiipImagineBundle` project. | ||
* | ||
* (c) /~https://github.com/liip/LiipImagineBundle/graphs/contributors | ||
* | ||
* For the full copyright and license information, please view the LICENSE.md | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Liip\ImagineBundle\Config\Filter\Type; | ||
|
||
use Liip\ImagineBundle\Config\Filter\Argument\Size; | ||
use Liip\ImagineBundle\Config\FilterInterface; | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
final class Downscale extends FilterAbstract implements FilterInterface | ||
{ | ||
const NAME = 'downscale'; | ||
|
||
/** | ||
* @var Size | ||
*/ | ||
private $max; | ||
|
||
/** | ||
* @var float | ||
*/ | ||
private $by; | ||
|
||
/** | ||
* @param Size $max | ||
* @param float|null $by sets the "ratio multiple" which initiates a proportional scale operation computed by multiplying all image sides by this value | ||
*/ | ||
public function __construct(Size $max, float $by = null) | ||
{ | ||
$this->max = $max; | ||
$this->by = $by; | ||
} | ||
|
||
public function getMax(): Size | ||
{ | ||
return $this->max; | ||
} | ||
|
||
public function getBy(): ?float | ||
{ | ||
return $this->by; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the `liip/LiipImagineBundle` project. | ||
* | ||
* (c) /~https://github.com/liip/LiipImagineBundle/graphs/contributors | ||
* | ||
* For the full copyright and license information, please view the LICENSE.md | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Liip\ImagineBundle\Config\Filter\Type; | ||
|
||
use Liip\ImagineBundle\Config\FilterInterface; | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
abstract class FilterAbstract implements FilterInterface | ||
{ | ||
const NAME = self::NAME; | ||
|
||
public function getName(): string | ||
{ | ||
return self::NAME; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the `liip/LiipImagineBundle` project. | ||
* | ||
* (c) /~https://github.com/liip/LiipImagineBundle/graphs/contributors | ||
* | ||
* For the full copyright and license information, please view the LICENSE.md | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Liip\ImagineBundle\Config\Filter\Type; | ||
|
||
use Liip\ImagineBundle\Config\FilterInterface; | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
final class Flip extends FilterAbstract implements FilterInterface | ||
{ | ||
const NAME = 'flip'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $axis; | ||
|
||
/** | ||
* @param string $axis possible values are: "x", "horizontal", "y", or "vertical" | ||
*/ | ||
public function __construct(string $axis) | ||
{ | ||
$this->axis = $axis; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we validate the values? does imagine provide constants for these? |
||
} | ||
|
||
public function getAxis(): string | ||
{ | ||
return $this->axis; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the backslashes here?