vendor/contao-community-alliance/events-contao-bindings/src/Subscribers/MessageSubscriber.php line 72

Open in your IDE?
  1. <?php
  2. /**
  3.  * This file is part of contao-community-alliance/events-contao-bindings
  4.  *
  5.  * (c) 2014-2018 The Contao Community Alliance
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  *
  10.  * This project is provided in good faith and hope to be usable by anyone.
  11.  *
  12.  * @package    ContaoCommunityAlliance\Contao\Bindings
  13.  * @subpackage Subscribers
  14.  * @author     Christian Schiffler <c.schiffler@cyberspectrum.de>
  15.  * @author     Tristan Lins <tristan.lins@bit3.de>
  16.  * @author     Sven Baumann <baumann.sv@gmail.com>
  17.  * @copyright  2018 The Contao Community Alliance.
  18.  * @license    https://github.com/contao-community-alliance/events-contao-bindings/blob/master/LICENSE LGPL-3.0
  19.  * @filesource
  20.  */
  21. namespace ContaoCommunityAlliance\Contao\Bindings\Subscribers;
  22. use Contao\CoreBundle\Framework\ContaoFrameworkInterface;
  23. use Contao\Message;
  24. use ContaoCommunityAlliance\Contao\Bindings\ContaoEvents;
  25. use ContaoCommunityAlliance\Contao\Bindings\Events\Message\AddMessageEvent;
  26. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  27. /**
  28.  * Subscriber for the news extension.
  29.  */
  30. class MessageSubscriber implements EventSubscriberInterface
  31. {
  32.     /**
  33.      * The contao framework.
  34.      *
  35.      * @var ContaoFrameworkInterface
  36.      */
  37.     protected $framework;
  38.     /**
  39.      * MessageSubscriber constructor.
  40.      *
  41.      * @param ContaoFrameworkInterface $framework The contao framework.
  42.      */
  43.     public function __construct(ContaoFrameworkInterface $framework)
  44.     {
  45.         $this->framework $framework;
  46.     }
  47.     /**
  48.      * Returns an array of event names this subscriber wants to listen to.
  49.      *
  50.      * @return array
  51.      */
  52.     public static function getSubscribedEvents()
  53.     {
  54.         return [
  55.             ContaoEvents::MESSAGE_ADD => 'addMessage',
  56.         ];
  57.     }
  58.     /**
  59.      * Add a message to the contao message array in the session.
  60.      *
  61.      * @param AddMessageEvent $event The event.
  62.      *
  63.      * @return void
  64.      */
  65.     public function addMessage(AddMessageEvent $event)
  66.     {
  67.         /** @var Message $messageAdapter */
  68.         $messageAdapter $this->framework->getAdapter(Message::class);
  69.         $messageAdapter->add($event->getContent(), 'TL_' strtoupper($event->getType()));
  70.     }
  71. }