Skip to content

Instantly share code, notes, and snippets.

@faiyazalam
Created May 15, 2018 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save faiyazalam/661dc3f87494ef90e06c04df06013325 to your computer and use it in GitHub Desktop.
Save faiyazalam/661dc3f87494ef90e06c04df06013325 to your computer and use it in GitHub Desktop.
How to modify post data in the request object - Symfony - PIMCORE ?
//In service file: /var/www/html/pimcore/src/AppBundle/Resources/config/services.yml
AppBundle\EventListener\TestListener:
tags:
- { name: kernel.event_listener, event: kernel.request }
//In listner file: /var/www/html/pf/src/AppBundle/EventListener/UserListener.php
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
class TestListener {
public function onKernelRequest(GetResponseEvent $event)
{
// - { name: kernel.event_listener, event: kernel.request }
$request = $event->getRequest();
//check if the parameter 'data' is present in the request.
if(!$request->request->has('data'))
{
return;
}
$data = $request->request->get("data");
if(empty($data['user']))
{
return;
}
//modify data here
//$data = $data;
$newData = array(
'data'=>$data
);
//replace the old data with the new modified data.
$request->request->replace($newData);
//done.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment