cphalcon
cphalcon copied to clipboard
Update Request.zep
The Http request service cannot invoke filterService from container.
Hello!
- Type: bug fix
- Link to issue: based on the documentation there: https://docs.phalcon.io/5.0/en/request#preset-sanitizers I implemented sanitizers on my Http request service with the following code:
public function register(DiInterface $di) : void
{
$di->setShared($this->serviceName, function () {
$request = new Request();
$request->setParameterFilters(
'id',[\Phalcon\Filter\Filter::FILTER_ABSINT],['post']
)
->setParameterFilters(
'title',
[
\Phalcon\Filter\Filter::FILTER_TRIM,
\Phalcon\Filter\Filter::FILTER_STRIPTAGS
],
['post']
)
->setParameterFilters(
'email',
[
\Phalcon\Filter\Filter::FILTER_EMAIL,
\Phalcon\Filter\Filter::FILTER_TRIM
],
['post']
)
;
return $request;
});
}
And then, i got an exception message, which means the DI container is null
"A dependency injection container is required to access the 'filter' service"
in this case, I have updated getFilterService() so that the Request Service can invoke system Filter properly.
In raising this pull request, I confirm the following:
- [x] I have read and understood the Contributing Guidelines
- [x] I have checked that another pull request for this purpose does not exist
- [x] I wrote some tests for this PR
Thanks Zike
@zikezhang Are you using Di or FactoryDefault for your container?
Hi @niden , I am using Phalcon\Di\FactoryDefault for the Http container.
I am wondering if we can rename private filterService = null; to private filter = null; like it's in the Cookie component.