-
Notifications
You must be signed in to change notification settings - Fork 730
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
Add foreach processor #1813
Add foreach processor #1813
Conversation
Note: I will do some other processor in the list, only did one for now because want to check :
|
- [Remove constructor](ruflin#1813 (comment)) - Fix processor name being "foreach_processor" instead of "processor" due to class name (note: 'Foreach' is reserved) - Fix ForeachProcessor.setProcessor method - Update ForeachProcessorTest, all tests runs locally
As Wouldn't a |
PHP is one of the few languages which doesn't allow the constructor overloading... And I often forgot that.
Similar behaviour can be made with public static class and private constructor: but thus mean that this class won't be instantiated like the other processors. Might be a bit strange as final user?
The setRawProcessor is needed to easily add a processor which doesn't exist as an Elastica class.
Yes of course. But while I'm thinking about it, the most frequent instance will be with AbstractProcessor. /**
* Foreach constructor.
*/
public function __construct(string $field, AbstractProcessor $processor)
{
$this->setField($field);
$this->setProcessor($processor);
} Thus if the user wants to use a custom processor: $processor = ForeachProcessor('field', null);
$processor->setRawProcessor(['remove' => ['field' => 'user_agent']]); And in other case: $processor = ForeachProcessor('field', new Remove('user_agent')); |
@ThibautSF I better understand now with your explanation. We can kind of simulate use of constructor overloading with: /**
* @param AbstractProcessor|array $processor
*/
public function __construct(string $field, $processor)
{
$this->setField($field);
if ($processor instanceof AbstractProcessor) {
$this->setProcessor($processor);
} elseif (\is_array($processor)) {
$this->setRawProcessor($processor);
} else {
throw new \TypeError('Expected xxx');
}
} That can later be replaced with native union type when dropping support for PHP versions < 8.0 Not sure if we have to support the raw processor format, but @ruflin will be of better help for this. |
I was working on /**
* Foreach constructor.
*
* @param AbstractProcessor $processor
*/
public function __construct(string $field, ?AbstractProcessor $processor)
{
$this->setField($field);
$this->setProcessor($processor);
} But your solution looks better. |
Sorry, a bit late to comment but I'm curious what we need to move this forward? @ThibautSF @deguif ? |
Should be OK Just, code will need to be a bit updated if there is any modification due to #1824 |
@ThibautSF can you rebase the PR. Overriding |
- [Remove constructor](ruflin#1813 (comment)) - Fix processor name being "foreach_processor" instead of "processor" due to class name (note: 'Foreach' is reserved) - Fix ForeachProcessor.setProcessor method - Update ForeachProcessorTest, all tests runs locally
First time rebasing a PR : Followed this guide https://github.com/edx/edx-platform/wiki/How-to-Rebase-a-Pull-Request |
It seems rebase has not worked as it should as there are lot of commit not introduced in this PR. |
Should be already allowed. EDIT: |
Co-authored-by: François-Xavier de Guillebon <[email protected]>
- [Remove constructor](ruflin#1813 (comment)) - Fix processor name being "foreach_processor" instead of "processor" due to class name (note: 'Foreach' is reserved) - Fix ForeachProcessor.setProcessor method - Update ForeachProcessorTest, all tests runs locally
Co-authored-by: François-Xavier de Guillebon <[email protected]>
- Remove _getBaseName() override - Remove an empty line in constructor
4369fe9
to
d275e1a
Compare
@ThibautSF should be good now. |
Merging this even though I assume we didn't really align yet on #1824 ;-) But we should not block contributions based on this discussion and we can add an alias at any time. |
This one shouldn't be impacted as it conflicts with reserved keywords and will need a |
Add Foreach processor (and test files)
Complete list in #1812