PHP code example of symfony-bro / notification-core

1. Go to this page and download the library: Download symfony-bro/notification-core library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

symfony-bro / notification-core example snippets




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;
    }
}


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(['[email protected]' => 'ACME SHOP LTD.'])
                ->setTo([
                    $customer->getEmail() => $customer->getName(),
                ])
                ->setBody('you can render content using some templating engine')
        );
    }
}