2017 © Pedro Peláez
 

library notification-core

Schedule bundle

image

symfony-bro/notification-core

Schedule bundle

  • Wednesday, May 16, 2018
  • by tigokr
  • Repository
  • 2 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 15 Versions
  • 0 % Grown

The README.md

Introduction

This library is provided to abstract transport layer of notification process., (*1)

Architecture

Transport layer

The main abstraction of the transport layer is \SymfonyBro\NotificationCore\Model\NotificationManagerInterface with only method notify(NotificationInterface $notification). The idea is that we should create a notification object for some event and send it with notification manager. So, client code knows nothing about how notification will be send., (*2)

We've created an abstract implementation for this interface — \SymfonyBro\NotificationCore\Model\AbstractNotificationManager. Internally it delegates job to formatter and driver objects., (*3)

Driver

Driver object implements \SymfonyBro\NotificationCore\Model\DriverInterface and responsible for sending a message. Message is another object implements \SymfonyBro\NotificationCore\Model\MessageInterface related to a specific driver. For example we have SwiftMailerDriver out of the box and it can send SwiftMailerMessage. But where do we get a message object?, (*4)

Formatter

There is formatter object which implements \SymfonyBro\NotificationCore\Model\FormatterInterface. The only purpose of formatter is creating a message object from a notification object., (*5)

Examples

Say, we have to send an email to the client if he makes new order. Suppose you already have some observer pattern implementation and you have listener for new order event. First we should create new notification class for this event:, (*6)

<?php

use SymfonyBro\NotificationCore\Model\NotificationInterface;
use App\Model\Order;

class OrderCreatedNotification implements NotificationInterface
{
    /**
     * @var Order
     */
    private $order;

    public function __construct(Order $order)
    {
        $this->order = $order;
    }

    /**
     * @return Order
     */
    public function getOrder(): Order
    {
        return $this->order;
    }
}

It should contains all required information, in example above it receives an Order object and we suppose that Order contains Customer object with some kind of contact information: $order->getCustomer()->getEmail()., (*7)

Then we have to create a formatter object:, (*8)

<?php
namespace App\Notifications\Order;

use App\Model\Order;
use SymfonyBro\NotificationCore\Driver\SwiftMailer\SwiftMailerMessage;
use SymfonyBro\NotificationCore\Model\FormatterInterface;
use SymfonyBro\NotificationCore\Model\MessageInterface;
use SymfonyBro\NotificationCore\Model\NotificationInterface;
use Swift_Message;

class OrderCreatedEmailFormatter implements FormatterInterface
{
    /**
     * @param NotificationInterface $notification
     * @return MessageInterface|OrderCreatedNotification
     */
    public function format(NotificationInterface $notification): MessageInterface
    {
        $customer = $notification->getOrder()->getCustomer();
        return new SwiftMailerMessage(
            $notification,
            (new Swift_Message('New order #'. $customer->getId()))
                ->setFrom(['noreply@acme-shop.com' => 'ACME SHOP LTD.'])
                ->setTo([
                    $customer->getEmail() => $customer->getName(),
                ])
                ->setBody('you can render content using some templating engine')
        );
    }
}

The Versions

16/05 2018

dev-master

9999999-dev

Schedule bundle

  Sources   Download

The Requires

 

The Development Requires

by Pavel Stepanets
by Artem Dekhtyar

notification

08/05 2018

0.4.1

0.4.1.0

Schedule bundle

  Sources   Download

The Requires

 

The Development Requires

by Pavel Stepanets
by Artem Dekhtyar

notification

17/04 2018

0.4.0

0.4.0.0

Schedule bundle

  Sources   Download

The Requires

 

The Development Requires

by Pavel Stepanets
by Artem Dekhtyar

notification

25/03 2018

0.3.0

0.3.0.0

Schedule bundle

  Sources   Download

The Requires

  • php >=7.0

 

The Development Requires

by Pavel Stepanets
by Artem Dekhtyar

notification

05/01 2018

0.2.4

0.2.4.0

Schedule bundle

  Sources   Download

The Requires

  • php >=7.0

 

The Development Requires

by Pavel Stepanets
by Artem Dekhtyar

notification

18/12 2017

0.2.3

0.2.3.0

Schedule bundle

  Sources   Download

The Requires

  • php >=7.0

 

The Development Requires

by Pavel Stepanets
by Artem Dekhtyar

notification

17/12 2017

0.2.2

0.2.2.0

Schedule bundle

  Sources   Download

The Requires

  • php >=7.0

 

The Development Requires

by Pavel Stepanets
by Artem Dekhtyar

notification

17/12 2017

0.2.1

0.2.1.0

Schedule bundle

  Sources   Download

The Requires

  • php >=7.0

 

The Development Requires

by Pavel Stepanets
by Artem Dekhtyar

notification

17/12 2017

0.2.0

0.2.0.0

Schedule bundle

  Sources   Download

The Requires

  • php >=7.0

 

The Development Requires

by Pavel Stepanets
by Artem Dekhtyar

notification

17/12 2017

dev-v2-dev

dev-v2-dev

Schedule bundle

  Sources   Download

The Requires

  • php >=7.0

 

The Development Requires

by Pavel Stepanets
by Artem Dekhtyar

notification

18/09 2017

0.1.3

0.1.3.0

Schedule bundle

  Sources   Download

The Requires

  • php >=7.0

 

The Development Requires

by Pavel Stepanets
by Artem Dekhtyar

notification

18/09 2017

0.1.2

0.1.2.0

Schedule bundle

  Sources   Download

The Requires

  • php >=7.0

 

The Development Requires

by Pavel Stepanets
by Artem Dekhtyar

notification

16/09 2017

dev-feature-fin_report

dev-feature-fin_report

Schedule bundle

  Sources   Download

The Requires

  • php >=7.0

 

The Development Requires

by Pavel Stepanets
by Artem Dekhtyar

notification

19/05 2017

0.1.1

0.1.1.0

Schedule bundle

  Sources   Download

The Requires

  • php >=7.0

 

The Development Requires

by Pavel Stepanets
by Artem Dekhtyar

notification

19/05 2017

0.1.0

0.1.0.0

Schedule bundle

  Sources   Download

The Requires

  • php >=7.0

 

The Development Requires

by Pavel Stepanets
by Artem Dekhtyar

notification