Closed danizord closed 7 years ago
@tmikaeld put the filters
inside additionalProperties
, your tests does not reflect this. Furthermore you can not just return a mixed
value from $model->filter()
when the expected return type is Result|ResultInterface|ResponseInterface
.
@danizord I guess you meant :)
Nope, @tmikaeld in your example at #133 you put the filters
in the additionalProperties
section, but @danizord put it on level up. So the test is not testing your described issue.
@Konafets Ah, ok, i tried both but none worked.
@Konafets not sure about @tmikaeld use case, but my use case is that I want to have a filter to "unwrap" the response result. If I place the filters
in the additionalProperties
section, it would run the filter for each scalar value, but I'd like to run the filter against the whole response model. Is it mergeable?
IMO a filter is intended to apply to every value a filter is defined. Personally I never used filters so far, so I have no experience with it. What you try to do has to be done on a different way. Filters are the wrong way.
@Konafets but since the model is a Parameter
itself, and the schema of models
has a filters
property, I think it makes sense to run these filters instead of simply ignoring them, no?
I may update the PR to pass and receive array
instead of ResutInterface
. What do you think?
@danizord Why i wanted to run the filter in the first place was to convert the object to an array and in this case i think the most expected result is an array anyway.
@danizord As I said before and the documentation + the doc header states, the filter is not intended to "unwrap" your response but "Run a value through the filters OR format attribute associated with parameter.".
Just because the filter method is there, it does not mean to use it in any possible way. Since Result uses the hasDataTrait
you can get any data from your response by $result->offsetGet()
or by implement an own Client and override the execute()
method.
class MyCustomClient extends GuzzleClient
{
/**
* @param CommandInterface $command
* @return ResultInterface
* @throws Exception
*/
public function execute(CommandInterface $command) : ResultInterface
{
$name = $command->getName();
$command->offsetSet('response', $this->getHttpClient()->getConfig('response'));
try {
$result = $this->executeAsync($command)->wait();
$model = $this->getDescription()->getOperation($name)->getResponseModel();
} catch (Exception $e) {
// Catch all exceptions we did not covered before. These should be logged in any case.
throw $e;
}
if (! empty($result) && $result->count() > 0) {
$result = new Result($result->offsetGet($model));
} else {
$result = new Result();
}
return $result;
}
}
Fixes https://github.com/guzzle/guzzle-services/issues/133