1515use Symfony \Component \HttpFoundation \Request ;
1616use Symfony \Component \HttpFoundation \Session \Flash \AutoExpireFlashBag ;
1717use Symfony \Component \HttpKernel \HttpKernelInterface ;
18- use Symfony \Component \HttpKernel \Event \FilterResponseEvent ;
1918use Symfony \Component \HttpKernel \KernelEvents ;
19+ use Symfony \Component \HttpKernel \Event \FilterControllerEvent ;
20+ use Symfony \Component \HttpKernel \Event \FilterResponseEvent ;
21+ use Symfony \Component \HttpKernel \Event \GetResponseEvent ;
2022use Symfony \Component \EventDispatcher \EventSubscriberInterface ;
2123
22- class RestKernelSuscriber implements EventSubscriberInterface
24+ class RestSubscriber implements EventSubscriberInterface
2325{
2426 /**
2527 *
2628 * @param Request $request
2729 * @param Array $trigger
2830 *
29- * @return Mixed false or content accepted
31+ * @return Mixed false or content accepted
3032 */
3133 public function checkAcceptedContent (Request $ request , $ acceptedContent )
3234 {
@@ -46,6 +48,24 @@ public function checkAcceptedContent(Request $request, $acceptedContent)
4648 return false ;
4749 }
4850
51+ public function postAnnotations (FilterControllerEvent $ event )
52+ {
53+ $ request = $ event ->getRequest ();
54+ $ restConfig = $ request ->attributes ->get ('_rest ' );
55+
56+ if ($ restConfig == false ) {
57+ return ;
58+ }
59+
60+ if ($ restConfig ->getPayloadMapping ()) {
61+ $ content = $ request ->getContent ();
62+ if (empty ($ content ) == false ) {
63+ $ payload = json_decode ($ content , true );
64+ $ request ->request ->add (array ($ restConfig ->getPayloadMapping () => $ payload ));
65+ }
66+ }
67+ }
68+
4969 public function onKernelResponse (FilterResponseEvent $ event )
5070 {
5171 if (HttpKernelInterface::MASTER_REQUEST !== $ event ->getRequestType ()) {
@@ -127,7 +147,8 @@ public function onKernelResponse(FilterResponseEvent $event)
127147 public static function getSubscribedEvents ()
128148 {
129149 return array (
130- KernelEvents::RESPONSE => array ('onKernelResponse ' , 0 ),
150+ KernelEvents::CONTROLLER => array ('postAnnotations ' , 0 ),
151+ KernelEvents::RESPONSE => array ('onKernelResponse ' , 0 )
131152 );
132153 }
133154}
0 commit comments