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 2 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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?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; | ||
|
||
final class Filter implements FilterInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $name; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $options = []; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* @param string $name | ||
*/ | ||
public function setName(string $name): void | ||
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'd rather use constructor arguments than setters 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. got it, will refactor it. |
||
{ | ||
$this->name = $name; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getOptions(): array | ||
{ | ||
return $this->options; | ||
} | ||
|
||
/** | ||
* @param array $options | ||
*/ | ||
public function setOptions(array $options): void | ||
{ | ||
$this->options = $options; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?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; | ||
|
||
use Liip\ImagineBundle\Factory\Config\FilterFactory; | ||
|
||
final class FilterBuilder implements FilterBuilderInterface | ||
{ | ||
/** | ||
* @var FilterFactory | ||
*/ | ||
private $filterFactory; | ||
|
||
/** | ||
* @param FilterFactory $filterFactory | ||
*/ | ||
public function __construct(FilterFactory $filterFactory) | ||
{ | ||
$this->filterFactory = $filterFactory; | ||
} | ||
|
||
/** | ||
* @param string $filterName | ||
* @param array $filterData | ||
* | ||
* @return FilterInterface | ||
*/ | ||
public function build(string $filterName, array $filterData): FilterInterface | ||
{ | ||
$filter = $this->filterFactory->create(); | ||
$filter->setName($filterName); | ||
$filter->setOptions($filterData); | ||
|
||
return $filter; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?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; | ||
|
||
interface FilterBuilderInterface | ||
{ | ||
/** | ||
* @param string $filterName | ||
* @param array $filterData | ||
* | ||
* @return FilterInterface | ||
*/ | ||
public function build(string $filterName, array $filterData): FilterInterface; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?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; | ||
|
||
interface 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. i would like to do a phpdoc that explains what a filter is (the definition for one image transformation operation) 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. @dbu could you provide an example ? cause I'm not sure that I understand this comment. 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.
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 |
||
{ | ||
/** | ||
* @return string | ||
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. we should say what the name is for. is it only for debugging purposes? do we match actual filters by filter class or by filter name? i think filters should be matched by filter name, to allow having the same class represent different filters. 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. ^ |
||
*/ | ||
public function getName(): string; | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getOptions(): array; | ||
|
||
/** | ||
* @param string $name | ||
*/ | ||
public function setName(string $name): void; | ||
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. imo the interface should not define setters. the whole definition is a read-only thing. 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. completely agree with you :) |
||
|
||
/** | ||
* @param array $options | ||
*/ | ||
public function setOptions(array $options): void; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?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; | ||
|
||
use Liip\ImagineBundle\Exception\InvalidArgumentException; | ||
|
||
final class FilterSet implements FilterSetInterface | ||
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. as discussed, rename this to |
||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $name; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $dataLoader; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $quality; | ||
|
||
/** | ||
* @var FilterInterface[] | ||
*/ | ||
private $filters = []; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getDataLoader(): string | ||
{ | ||
return $this->dataLoader; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getQuality(): int | ||
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. this should have a phpdoc explaining what it is. (resp, as rob says the jpg quality and the png compression level values should have that doc, to explain the value range) |
||
{ | ||
return $this->quality; | ||
} | ||
|
||
/** | ||
* @return FilterInterface[] | ||
*/ | ||
public function getFilters(): array | ||
{ | ||
return $this->filters; | ||
} | ||
|
||
/** | ||
* @param string $name | ||
*/ | ||
public function setName(string $name): void | ||
{ | ||
$this->name = $name; | ||
} | ||
|
||
/** | ||
* @param string|null $dataLoader | ||
*/ | ||
public function setDataLoader($dataLoader): void | ||
{ | ||
$this->dataLoader = (string) $dataLoader; | ||
} | ||
|
||
/** | ||
* @param int $quality | ||
*/ | ||
public function setQuality(int $quality): void | ||
{ | ||
$this->quality = $quality; | ||
} | ||
|
||
/** | ||
* @param FilterInterface[] $filters | ||
*/ | ||
public function setFilters(array $filters): void | ||
{ | ||
foreach ($filters as $filter) { | ||
if (!($filter instanceof FilterInterface)) { | ||
throw new InvalidArgumentException('Unknown filter provided.'); | ||
} | ||
} | ||
$this->filters = $filters; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?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; | ||
|
||
use Liip\ImagineBundle\Factory\Config\FilterSetFactory; | ||
|
||
final class FilterSetBuilder implements FilterSetBuilderInterface | ||
{ | ||
/** | ||
* @var FilterSetFactory | ||
*/ | ||
private $filterSetFactory; | ||
|
||
/** | ||
* @var FilterBuilderInterface | ||
*/ | ||
private $filterBuilder; | ||
|
||
/** | ||
* @param FilterSetFactory $filterSetFactory | ||
* @param FilterBuilderInterface $filterBuilder | ||
*/ | ||
public function __construct(FilterSetFactory $filterSetFactory, FilterBuilderInterface $filterBuilder) | ||
{ | ||
$this->filterSetFactory = $filterSetFactory; | ||
$this->filterBuilder = $filterBuilder; | ||
} | ||
|
||
/** | ||
* @param string $filterSetName | ||
* @param array $filterSetData | ||
* | ||
* @return FilterSetInterface | ||
*/ | ||
public function build(string $filterSetName, array $filterSetData): FilterSetInterface | ||
{ | ||
$filterSet = $this->filterSetFactory->create(); | ||
$filterSet->setName($filterSetName); | ||
$filterSet->setDataLoader($filterSetData['data_loader']); | ||
$filterSet->setQuality($filterSetData['quality']); | ||
|
||
if (!empty($filterSetData['filters'])) { | ||
$filters = []; | ||
foreach ($filterSetData['filters'] as $filterName => $filterData) { | ||
$filters[] = $this->filterBuilder->build($filterName, $filterData); | ||
} | ||
$filterSet->setFilters($filters); | ||
} | ||
|
||
return $filterSet; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?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; | ||
|
||
interface FilterSetBuilderInterface | ||
{ | ||
/** | ||
* @param string $filterSetName | ||
* @param array $filterSetData | ||
* | ||
* @return FilterSetInterface | ||
*/ | ||
public function build(string $filterSetName, array $filterSetData): FilterSetInterface; | ||
} |
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.
once you implemented all filters, this will become obsolete, right?
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.
done