ソースを参照

Use Symfony addFlash method

Sullivan SENECHAL 10 年 前
コミット
8d7e3694b1
2 ファイル変更13 行追加3 行削除
  1. 9 3
      Controller/CRUDController.php
  2. 4 0
      Tests/Controller/CRUDControllerTest.php

+ 9 - 3
Controller/CRUDController.php

@@ -1230,12 +1230,18 @@ class CRUDController extends Controller
      *
      * @param string $type
      * @param string $message
+     *
+     * @TODO Remove this method when bumping requirements to Symfony >= 2.6
      */
     protected function addFlash($type, $message)
     {
-        $this->get('session')
-             ->getFlashBag()
-             ->add($type, $message);
+        if (method_exists('Symfony\Bundle\FrameworkBundle\Controller\Controller', 'addFlash')) {
+            parent::addFlash($type, $message);
+        } else {
+            $this->get('session')
+                ->getFlashBag()
+                ->add($type, $message);
+        }
     }
 
     /**

+ 4 - 0
Tests/Controller/CRUDControllerTest.php

@@ -295,6 +295,10 @@ class CRUDControllerTest extends \PHPUnit_Framework_TestCase
                     return true;
                 }
 
+                if ($id == 'session') {
+                    return true;
+                }
+
                 return false;
             }));