Notification-bundle

Bundle for notification lib

View the Project on GitHub FunkyMonkeyLabs/notification-bundle

What's that?

FML/Notification lib allows to send notification through different channels during application runtime. Library can collect many messages to many users and send it to them once, when application is going down.

FML/NotificationBundle is wrapping Notification Library so you can send notification easily in your projects when you are using Symfony2 Framework.

During runtime, you can register messages. That's it. When there appears terminate event, NotificationBundle will send all of the messages.

Instalation

composer

$ php composer.phar require fml/notification-bundle:1.3.*
# app/AppKernel.php

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            ...
            new FML\Notification\NotificationBundle\FMLNotificationBundle()
        );
    }
}

Usage

By default there is a one channel - mail channel. It requires mailer service. If you want to send notification to user Patryk with e-mail address contact@funkymonkeylabs.pl, with message "Hello Patryk", you have to write:

class SomeController extends Controller
{
    public function indexAction(Request $request)
    {
        $recipient = new FML\Notification\NotificationBundle\Notification\Recipient\Recipient();
        $recipient
            ->setAddress('contact@funkymonkeylabs.pl')
            ->setName('Patryk');

        $message = new FML\Notification\NotificationBundle\Message\PlainMailMessage();

        $sender = $this->get('fml.notification.sender'); // get sender instance
        $sender->addMessage('fml.meetings.notification.message.meeting', $recipient, array(
            'name' => $recipient->getName()
        )); // add message to queue
    }
}

Adding channels

You can also add your own channel (for example if you are going to send SMS messages).

// src/Acme/DemoBundle/AcmeDemoBundle.php
namespace Acme\DemoBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Acme\DemoBundle\Channel\SMSChannel;

class AcmeDemoBundle extends Bundle
{
    public function build(ContainerBuilder $container)
    {
        parent::build($container);

        $channel = new SMSChannel();

        $sender = $container->get('fml.meetings.sender');
        $sender->addChannel($channel);
    }
}

Authors and Contributors

@abdulklarapl Patryk Szlagowski

Support or Contact

Having trouble with library? Check https://github.com/FunkyMonkeyLabs/notification-bundle and give us some info! You can create issue as well.