-
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
Conversation
Overalls, this looks great. I do have some ideas I've been wanting to implement regarding filter-sets/filter that would be good to bring up now. The number of times people confuse the difference between filter-sets and filters is countless, I submit we should change the terminology of filter-set to "instructions" or something different. Thoughts? Other naming ideas? The "quality" setting is also going to be deprecated because we now have "png_compression_level" and "jpeg_quality" now instead, so this interface should likely accommodate those new options (this has already been done in the underlying imagine library). Also, do we need interfaces for classes we're marking as final? It seems like possibly extra, unnecessary code to maintain if we aren't intending it to be an extension point. |
Also, with one of the PRs I'm converting from |
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.
good idea with expressing the configuration as objects. i think the basic structure is good.
as discussed before, i am not sure if the interfaces add all that much. though the implementation being final is not an argument against interfaces, actually the opposite. if somebody wants to change something, they have to implement the interface themselves. with the config classes being final, you can't adjust them. so overall i am ok to keep the interfaces.
could it make sense to make the filter classes specific to the type of filter they are? then instead of generic "options" we would have specific getters for width, height, blur factor, whatever the filter is doing... that would make the configuration much more explicit.
i would drop the setters from the interfaces, and also from the implementations and use constructor arguments instead, to make the configuration immutable. if we do that, it also makes sense to merge the factory and builder classes, as setting the information is no longer defined in the interface. imho that simplifies the codebase and makes it more clear.
people confuse the difference between filter-sets and filters is countless, I submit we should change the terminology
in rokka.io we call the filter-set "stack". what would you think of that name? oderwise, maybe "ImageFormat", as in the end it defines the format for one image. "instructions" is a bit weird as its just a different interpretation of what a filter is.
and should we call the thing now called filter a FilterDefinition? its more verbose, but in the context of the classes using these definitions, there are also the "actual" imagine filters which transform the image. this configuration container class only represents the definition for the filter, not the actual filter ;-)
The "quality" setting is also going to be deprecated because we now have "png_compression_level" and "jpeg_quality"
makes sense. is the configuration in the bundle already transformed in that way? do we currently use quality 1-10 for png and 100-1 for jpeg compression?
namespace
that makes sense to me, lets move the filters and stacks there.
Config/FilterInterface.php
Outdated
|
||
namespace Liip\ImagineBundle\Config; | ||
|
||
interface FilterInterface |
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.
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
/**
* A filter contains the configuration for an image transformation operation.
*
* The type of operation is defined by the filter class. The operation parameters are specific to
* the filter.
*/
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
Config/FilterInterface.php
Outdated
/** | ||
* @param string $name | ||
*/ | ||
public function setName(string $name): void; |
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
completely agree with you :)
Config/FilterSet.php
Outdated
/** | ||
* @return int | ||
*/ | ||
public function getQuality(): int |
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.
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)
Config/Filter.php
Outdated
/** | ||
* @param string $name | ||
*/ | ||
public function setName(string $name): void |
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.
i'd rather use constructor arguments than setters
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.
got it, will refactor it.
Anyway, thanks for all the hard work @maximgubar. The PR looks solid and I'm excited to get it included. |
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.
nice, i like it! i would love to bring down the number of interfaces and meta infrastructure classes a bit, see some of my comments.
Config/Filter/Type/Thumbnail.php
Outdated
|
||
/** | ||
* @param string $name | ||
* @param array $size |
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.
can you specify what kind of array this is? is it a hashmap with width and height?
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
interface FilterFactoryInterface | ||
{ | ||
/** | ||
* @return string |
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.
can we say that the name must match the Filter::getName that this factory handles?
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
Config/FilterFactoryCollection.php
Outdated
private $filterFactories; | ||
|
||
/** | ||
* FilterCollection constructor. |
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.
i'd remove docblocks that don't add any information over whats in the php code
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
Config/FilterFactoryCollection.php
Outdated
*/ | ||
public function __construct(FilterFactoryInterface ...$filterFactories) | ||
{ | ||
$this->filterFactories = $filterFactories; |
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.
imho we should convert this to a hashmap with name => factory so that we don't have to loop over the array in getFilterFactoryByName
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
|
||
use Liip\ImagineBundle\Factory\Config\FilterFactoryInterface; | ||
|
||
interface FilterFactoryCollectionInterface |
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.
imho there is only one way how this can be implemented and hence no point in having an interface
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
Resources/config/imagine.xml
Outdated
<service id="Liip\ImagineBundle\Factory\Config\Filter\StripFactory" alias="liip_imagine.factory.config.filter.strip"/> | ||
|
||
<service id="liip_imagine.factory.config.filter.thumbnail" class="Liip\ImagineBundle\Factory\Config\Filter\ThumbnailFactory" /> | ||
<service id="Liip\ImagineBundle\Factory\Config\Filter\ThumbnailFactory" alias="liip_imagine.factory.config.filter.thumbnail"/> |
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.
i don't think that we need an autowiring capable alias for these. they should be private services not useable outside of DI configuration
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
Resources/config/imagine.xml
Outdated
<argument type="service" id="liip_imagine.factory.config.filter.strip"/> | ||
<argument type="service" id="liip_imagine.factory.config.filter.thumbnail"/> | ||
</service> | ||
<service id="Liip\ImagineBundle\Config\FilterFactoryCollection" alias="liip_imagine.config.filter_factory_collection"/> |
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.
neither do we need autowiring for this. the only thing that should be available for autowiring should be the actual configuration object.
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
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.
@dbu, btw, do we need to have SF4 compatibility ?
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.
it would be nice, but i would not mix it into this pull request.
if we have new services that should be autowire-enabled, we can already define the right alias here, but i would not do anything outside the scope of modeling the configuration.
Config/FilterSetCollection.php
Outdated
* @param FilterConfiguration $filterConfiguration | ||
* @param FilterSetBuilderInterface $filterSetBuilder | ||
*/ | ||
public function __construct(FilterConfiguration $filterConfiguration, FilterSetBuilderInterface $filterSetBuilder) |
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.
does it make sense to use the FilterConfiguration object? looks to me like that is a previous attempt at this problem that did not go far enough? it smells like we should deprecate FilterConfiguration and pass the plain array here, or not?
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
Config/FilterSetCollection.php
Outdated
|
||
/** | ||
* @param FilterConfiguration $filterConfiguration | ||
* @param FilterSetBuilderInterface $filterSetBuilder |
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.
having factories for so many things, why do we not have a factory for the StackCollection? we could then define the public service for this as a thing that uses the StackCollectionFactory, and not have the value object that is used outside have the factory in it. the FilterSetBuilder could take that role, to not explode the number of infrastructure classes that we use.
for the symfony config, it would look like this: https://symfony.com/doc/current/service_container/factories.html
Config/Filter.php
Outdated
|
||
namespace Liip\ImagineBundle\Config; | ||
|
||
final class Filter implements FilterInterface |
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
Config/Filter/Type/Background.php
Outdated
/** | ||
* @return string | ||
*/ | ||
public function getName(): string |
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.
Max, this is wrong. If color is optional - use ?string
as return type. Also phpdocs which duplicates actual typehints/return types are useless.
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.
thanks for the hint, will refactor.
Config/Filter/Type/Crop.php
Outdated
|
||
/** | ||
* @param string $name | ||
* @param array $start start coordinates {x,y} |
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 not provide value object for Point
?
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.
good idea, will add it
/** | ||
* @param FilterFactoryInterface ...$filterFactories | ||
*/ | ||
public function __construct(FilterFactoryInterface ...$filterFactories) |
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.
Variadic here looks so strange. IMHO it is better use array of FilterFactoryInterface
and instanceof/private method to ensure type of each item in array.
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.
got your point, but how usage of array and additional checks of type is better ?
since this object actually plays a role of collection and it is constructed with FilterFactoryInterface(s) why just not declare it directly ?
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.
as you loop over the parameter anyways, you could also do an instanceof check, and have the @param FilterFactoryInterface[] $filterFactories
to allow code sniffers to detect errors.
if we ever need to add an (optional) constructor argument, the current form will be a problem as we can't add anything else without a BC break.
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 would we ever need to to add something to constructor of this class ?
the purpose of this object is to store FilterFactoryInterfaces only and thats it. it shouldn't contain any logic. tbh, in this case specifically, I don't see advantages of array implementation.
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.
i don't mind much either way.
thinking of it, we should mark all the factory part as @internal
to tell people to not use that in their project. the exposed thing is the configuration object model, not the factories to build it. if we do that we can also leave the variadic imho.
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.
yes, because final
means you can't extend the class, but @internal
means you should not interact with it at all, e.g. instantiate it in your code and so something with it.
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
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.
I guess within Symfony the pattern used most often is an add()
method to build the collection instead of a constructor argument. obviously this has more performance overhead however. I think this is an interesting approach but since variadic in user land is still a new concept there is less experience with it.
but I wonder if it wouldn't be better to use a factory method instead of the constructor. ie. something like:
class FilterFactoryCollection
{
static public function createFromList(FilterFactoryInterface ...$filterFactories)
{
$collection = new self;
$collection->addList(FilterFactoryInterface ...$filterFactories);
}
}
this keeps the options open for if we ever do need to add anything to the constructor. while keeping the convenience and more or less the overhead reduction benefits.
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.
this object has only one purpose, to store the FilterFactoryInterfaces (which are clearly its dependencies and should be specified), I dont see any valid case which would lead to altering constructor. Also, I am not sure is it a good practice to do indirect object injections (via setters).
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.
ok lets keep it as proposed. like I said, a good chance of this feeling "weird" is simply the lack of experience with variadic in user land .. and honestly this is not the most "risky" place .. if we do in the end realize we need support additional constructor parameters .. we can then still use a static factory method for that case.
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.
added a bunch of small review comments. but i like where this is going, i think its coming to a good form.
Config/Filter/Type/Background.php
Outdated
|
||
/** | ||
* @param string $name | ||
* @param string|null $color |
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.
i am ok with using a string for the $color, but we should explain here what it is. RRGGBB? with optional transparency?
Config/Filter/Type/Background.php
Outdated
/** | ||
* @param string $name | ||
* @param string|null $color | ||
* @param string|null $transparency |
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.
we should state the range of this. 0 to 100? or 0 to 1? or something else?
Config/Filter/Type/Background.php
Outdated
* @param string $name | ||
* @param string|null $color | ||
* @param string|null $transparency | ||
* @param string|null $position |
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.
is that a list of keywords like TOP|LEFT|BOTTOM|RIGHT, or something else?
Config/Filter/Type/Background.php
Outdated
* @param string|null $color | ||
* @param string|null $transparency | ||
* @param string|null $position | ||
* @param array $size |
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.
keys x and y? or do we use a value object for this?
Config/Filter/Type/Downscale.php
Outdated
/** | ||
* @return float|null | ||
*/ | ||
public function getBy() |
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.
: ?float
instead of the docblock
*/ | ||
public function create(array $options): FilterInterface | ||
{ | ||
$color = isset($options['color']) ? $options['color'] : null; |
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.
the most condensed for these checks would be $color = $options['color'] ?? null;
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.
is it a typo ?
should it be like this ?
$color = $options['color'] ?: null;
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.
no. that will generate a warning when the index 'color' is not set. ?? is the null coalesce operator introduced in PHP 7 to shorten exactly the construct you used above.
public function create(array $options): FilterInterface | ||
{ | ||
$mode = ImageInterface::INTERLACE_LINE; | ||
if (!empty($options['mode'])) { |
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 empty and not isset? i'd go with the pattern $mode = $options['mode'] ?? ImageInterface::INTERLACE_LINE;
public function create(array $options): FilterInterface | ||
{ | ||
$size = []; | ||
if (isset($options['size']) && is_array($options['size'])) { |
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.
this is silently ignoring non-array size options, which is a problem imho. we should do the $size = $options['size'] ?? [];
. the constructor type declaration on $size will detect if the size option has been set to an invalid value.
Factory/Config/StackFactory.php
Outdated
* @param string $name | ||
* @param string|null $dataLoader | ||
* @param int|null $quality | ||
* @param array $filters |
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.
FilterInterface[]
Factory/Config/StackFactory.php
Outdated
*/ | ||
public function create(string $name, string $dataLoader = null, int $quality = null, array $filters) | ||
{ | ||
return new Stack($name, $dataLoader, $quality, $filters); |
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.
also, is there value to use a factory for this over just doing new Stack()
in the place where we need the stack? feels to me like the factory is too much abstraction.
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.
using new
is breaking DI principle. it makes it hardcoded and non-extendable and not testable.
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.
i don't see the problem. we don't want a mock stack anywhere, its a value object. to me it looks overengineered with this. we do not need to DI what kind of stack is created as its just a value object. but its not a huge deal either.
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.
we already mock it in our unit tests
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.
i don't see the need for mocking the Stack object in a unit test, its straightforward enough imho. yes, its not a perfectly atomic unit test, but good enough as all of the build process is just infrastructure code to build the configuration object.
Config/Filter/Type/Background.php
Outdated
* @param string|null $position | ||
* @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 comment
The 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 comment
The 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 comment
The 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.
Config/Filter/Argument/Size.php
Outdated
*/ | ||
private $height; | ||
|
||
public function __construct(int $width = null, int $height = null) |
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.
Does size without width and height has any business value? Same for point. It looks like incomplete/invalid object. If Size
is optional for some operations - maybe se can use typehing ?Size
in this operations
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.
@Koc there are cases, when one of the dimensions could be null
, how would you suggest to implement it if this approach causes doubts ?
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.
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."
fixed static tests
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.
there are some comments that seem to have slipped through. and some more phpdoc that we can remove because it does not provide extra information.
the only larger bit i don't like is that the filter names are arguments and the constant is in the factories. i would instead put the constant into the filter class and reference it from the factory, and not have a constructor argument $name in the filters, but use the constant in getName
Config/Filter/Type/AutoRotate.php
Outdated
private $name; | ||
|
||
/** | ||
* @param string $name |
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.
lets remove this, its redundant
Config/Filter/Type/Interlace.php
Outdated
|
||
/** | ||
* @param string $name | ||
* @param string $mode |
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.
^
* @param float|null $heighten | ||
* @param float|null $widen | ||
* @param float|null $increase | ||
* @param float|null $scale |
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.
please remove this phpdoc as it does not add anything
Config/Filter/Type/Strip.php
Outdated
private $name; | ||
|
||
/** | ||
* @param string $name |
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.
please remove
Config/Filter/Type/Thumbnail.php
Outdated
* @param Size $size | ||
* @param string|null $mode | ||
* @param bool|null $allowUpscale | ||
* @param string|null $filter |
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.
please remove the docblock as it contains no information
Config/StackBuilder.php
Outdated
* @param string $filterSetName | ||
* @param array $filterSetData | ||
* | ||
* @return StackInterface |
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.
please remove, this is all visible in the method signature
Config/StackCollection.php
Outdated
final class StackCollection | ||
{ | ||
/** | ||
* @var array |
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.
^
Config/StackCollection.php
Outdated
/** | ||
* @var array | ||
*/ | ||
private $filterSets = []; |
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.
^
Config/StackCollection.php
Outdated
|
||
/** | ||
* @param StackBuilderInterface $stackBuilder | ||
* @param array $filtersConfiguration |
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.
please remove, its all in the method signature
Config/StackInterface.php
Outdated
/** | ||
* @return string|null | ||
*/ | ||
public function getDataLoader(); |
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.
as we are on php 7.1 or better, please use the return type declaration getDataLoader(): ?string
and remove the phpdoc. same for getQuality
Config/Filter/Type/Background.php
Outdated
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
final class Background extends FilterAbstract implements FilterInterface |
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.
you can remove the implements FilterInterface
because thats already given by extending FilterAbstract
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
Config/StackBuilderInterface.php
Outdated
* @param string $filterSetName | ||
* @param array $filterSetData | ||
* | ||
* @return StackInterface |
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.
this does not add anything over the phpdoc, lets remove it
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
interface FilterFactoryInterface | ||
{ | ||
/** | ||
* Filter name |
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.
^
* @param int|null $quality | ||
* @param FilterInterface[] $filters | ||
* | ||
* @return Stack |
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.
could we instead do the return type declaration on the method itself?
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
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.
i don't see any further things that i would want to change. i vote for merge (squashing commits). @robfrawley are you okay with that?
- optional return types - typo in Paste filter name
@robfrawley i would prefer to have some final feedback from you before we merge this. do you have time to look at this soonish? |
if (false === mb_strpos($path, '..'.DIRECTORY_SEPARATOR) && | ||
false === mb_strpos($path, DIRECTORY_SEPARATOR.'..') && | ||
false !== file_exists($absolute = $root.DIRECTORY_SEPARATOR.$path) | ||
if (false === mb_strpos($path, '..'.\DIRECTORY_SEPARATOR) && |
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?
Binary/Locator/FileSystemLocator.php
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
why the backslashes here?
@@ -127,7 +127,7 @@ private function getBundleResourcePaths(ContainerBuilder $container) | |||
} | |||
|
|||
return array_map(function ($path) { | |||
return $path.DIRECTORY_SEPARATOR.'Resources'.DIRECTORY_SEPARATOR.'public'; | |||
return $path.\DIRECTORY_SEPARATOR.'Resources'.\DIRECTORY_SEPARATOR.'public'; |
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?
Tests/AbstractTest.php
Outdated
@@ -50,8 +50,8 @@ | |||
|
|||
protected function setUp() | |||
{ | |||
$this->fixturesPath = realpath(__DIR__.DIRECTORY_SEPARATOR.'Fixtures'); | |||
$this->temporaryPath = sys_get_temp_dir().DIRECTORY_SEPARATOR.'liip_imagine_test'; | |||
$this->fixturesPath = realpath(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures'); |
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?
/** | ||
* @param FilterFactoryInterface ...$filterFactories | ||
*/ | ||
public function __construct(FilterFactoryInterface ...$filterFactories) |
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.
I guess within Symfony the pattern used most often is an add()
method to build the collection instead of a constructor argument. obviously this has more performance overhead however. I think this is an interesting approach but since variadic in user land is still a new concept there is less experience with it.
but I wonder if it wouldn't be better to use a factory method instead of the constructor. ie. something like:
class FilterFactoryCollection
{
static public function createFromList(FilterFactoryInterface ...$filterFactories)
{
$collection = new self;
$collection->addList(FilterFactoryInterface ...$filterFactories);
}
}
this keeps the options open for if we ever do need to add anything to the constructor. while keeping the convenience and more or less the overhead reduction benefits.
maybe we should have a 2.1 branch for this? or should we actually start using master again for future minor/major new versions? |
@lsmith77 we started to use |
In this PR I propose to introduce a service, which retrieves filter_sets, filters configuration and exposes it via interfaces.