benIT /
e-media
| 1 | <?php |
||
| 2 | |||
| 3 | namespace AppBundle\Controller; |
||
| 4 | |||
| 5 | trait ControllerUtilsTrait |
||
| 6 | { |
||
| 7 | public static $flashSuccess = 'success'; |
||
| 8 | public static $flashInfo = 'info'; |
||
| 9 | public static $flashWarning = 'warning'; |
||
| 10 | public static $flashDanger = 'danger'; |
||
| 11 | |||
| 12 | protected function flashMessage($type, $message = null) |
||
| 13 | { |
||
| 14 | $supportedTypes = [self::$flashSuccess, self::$flashInfo, self::$flashWarning, self::$flashDanger]; |
||
| 15 | if (!in_array($type, $supportedTypes)) { |
||
| 16 | throw new \LogicException(sprintf('""%s" type is not supported')); |
||
| 17 | } |
||
| 18 | if (!$this->container->has('session')) { |
||
| 19 | throw new \LogicException('You can not use the addFlash method if sessions are disabled.'); |
||
| 20 | } |
||
| 21 | if (!$message) { |
||
| 22 | $message = $this->get('translator')->trans('flash.'.$type.'.message', [], 'common'); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 23 | } |
||
| 24 | |||
| 25 | $this->container->get('session')->getFlashBag()->add($type, $message); |
||
| 26 | } |
||
| 27 | } |
||
| 28 |