-
Notifications
You must be signed in to change notification settings - Fork 202
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
Define API params in order to be able to filter correctly #413
Changes from 3 commits
436f688
eacb31f
964e40c
aeba2c1
a5172d1
9cc013d
71685e0
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 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -11,6 +11,13 @@ | |||||||||
|
||||||||||
class Api implements ApiInterface | ||||||||||
{ | ||||||||||
public const GLOBAL_API_PARAMS = [ | ||||||||||
'p', // preset | ||||||||||
'q', // quality | ||||||||||
'fm', // format | ||||||||||
's', // signature | ||||||||||
]; | ||||||||||
|
||||||||||
/** | ||||||||||
* Intervention image manager. | ||||||||||
*/ | ||||||||||
|
@@ -23,6 +30,13 @@ class Api implements ApiInterface | |||||||||
*/ | ||||||||||
protected array $manipulators; | ||||||||||
|
||||||||||
/** | ||||||||||
* API parameters. | ||||||||||
* | ||||||||||
* @var list<string> | ||||||||||
*/ | ||||||||||
protected array $apiParams; | ||||||||||
|
||||||||||
/** | ||||||||||
* Create API instance. | ||||||||||
* | ||||||||||
|
@@ -33,6 +47,7 @@ public function __construct(ImageManager $imageManager, array $manipulators) | |||||||||
{ | ||||||||||
$this->setImageManager($imageManager); | ||||||||||
$this->setManipulators($manipulators); | ||||||||||
$this->setApiParams(); | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
|
@@ -116,4 +131,32 @@ public function encode(ImageInterface $image, array $params): string | |||||||||
|
||||||||||
return $encoded->toString(); | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Sets the API parameters for all manipulators. | ||||||||||
* | ||||||||||
* @return list<string> | ||||||||||
*/ | ||||||||||
public function setApiParams(): array | ||||||||||
{ | ||||||||||
$this->apiParams = self::GLOBAL_API_PARAMS; | ||||||||||
|
||||||||||
foreach ($this->manipulators as $manipulator) { | ||||||||||
foreach ($manipulator->getApiParams() as $param) { | ||||||||||
$this->apiParams[] = $param; | ||||||||||
} | ||||||||||
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.
Suggested change
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 was over-complicating this, thanks for pointing it out! |
||||||||||
} | ||||||||||
|
||||||||||
return $this->apiParams = array_values(array_unique($this->apiParams)); | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Retun the list of API params. | ||||||||||
* | ||||||||||
* @return list<string> | ||||||||||
*/ | ||||||||||
public function getApiParams(): array | ||||||||||
{ | ||||||||||
return $this->apiParams; | ||||||||||
} | ||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,13 @@ public function getParam(string $name): mixed | |
: null; | ||
} | ||
|
||
/** | ||
* Get the names of the manipulator API parameters. | ||
* | ||
* @return list<string> | ||
*/ | ||
abstract public function getApiParams(): array; | ||
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 don't need this abstract method because it is defined already in ManipulatorInterface 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 agree, I was following what was done for the |
||
|
||
/** | ||
* Perform the image manipulation. | ||
* | ||
|
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 loop through each instead of using array merge?