-
-
Save faiyazalam/661dc3f87494ef90e06c04df06013325 to your computer and use it in GitHub Desktop.
How to modify post data in the request object - Symfony - PIMCORE ?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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