Skip to content

Conversation

zikezhang
Copy link
Contributor

The Http request service cannot invoke filterService from container.

Hello!

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:

  • I have read and understood the Contributing Guidelines
  • I have checked that another pull request for this purpose does not exist
  • I wrote some tests for this PR

Thanks
Zike

The Http request service cannot invoke filterService from container.
@niden
Copy link
Member

niden commented Nov 11, 2023

@zikezhang Are you using Di or FactoryDefault for your container?

@zikezhang
Copy link
Contributor Author

Hi @niden , I am using Phalcon\Di\FactoryDefault for the Http container.

@zikezhang
Copy link
Contributor Author

I am wondering if we can rename private filterService = null; to private filter = null; like it's in the Cookie component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants