Skip to content
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

Update Request.zep #16464

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Update Request.zep #16464

wants to merge 1 commit into from

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