-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
recreate BackedEnums when applying Manipulations #3584
Conversation
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 you add a test case to make sure this fix solves the problem?
src/Conversions/Manipulations.php
Outdated
@@ -52,6 +60,34 @@ public function isEmpty(): bool | |||
public function apply(ImageDriver $image): void | |||
{ | |||
foreach ($this->manipulations as $manipulationName => $parameters) { | |||
switch($manipulationName){ |
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 you use a match
operator instead?
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.
What do you think about using neither match nor switch. Just recreate all Enums if the parameter is present independent of thy type of manipulation
switch($manipulationName){ | |
(isset($parameters['type'])) && $parameters['type'] = BorderType::from($parameters['type']) ; | |
(isset($parameters['fit'])) && $parameters['fit'] = Fit::from($parameters['fit']); | |
(isset($parameters['position'])) && $parameters['position'] = AlignPosition::from($parameters['position']); | |
(isset($parameters['colorFormat'])) && $parameters['colorFormat'] = ColorFormat::from($parameters['colorFormat']); | |
(isset($parameters['constraints'])) && $parameters['constraints'] = Constraint::from($parameters['constraints']); | |
(isset($parameters['position'])) && $parameters['position'] = CropPosition::from($parameters['position']); | |
(isset($parameters['fit'])) && $parameters['fit'] = Fit::from($parameters['fit']); | |
(isset($parameters['flip'])) && $parameters['flip'] = FlipDirection::from($parameters['flip']); |
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 think a match we be more clear in this case
src/Conversions/Manipulations.php
Outdated
@@ -52,6 +60,34 @@ public function isEmpty(): bool | |||
public function apply(ImageDriver $image): void | |||
{ | |||
foreach ($this->manipulations as $manipulationName => $parameters) { | |||
switch($manipulationName){ | |||
case 'border': | |||
(isset($parameters['type'])) && $parameters['type'] = BorderType::from($parameters['type']) ; |
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.
(isset($parameters['type'])) && $parameters['type'] = BorderType::from($parameters['type']) ; | |
(isset($parameters['type'])) && $parameters['type'] = BorderType::from($parameters['type']); |
This reverts commit ec8f1a8.
There is also valid usage without named parameters $media->manipulations = [
'default' => [
'border' => [
1,
BorderType::Expand,
'000000'
]
]
]; I see 2 solutions there:
Obviously reflection would be better, but there performance concerns, so it needs benchmarking. I could take over this issue as this also need for my use case |
Fixes Issue #3582