PHP code example of demroos / notification-bundle
1. Go to this page and download the library: Download demroos/notification-bundle 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/ */
demroos / notification-bundle example snippets
<?
/**
* Class NotificationController
* @package App\Controller\Api
* @Route("/notification")
*/
class NotificationController extends ApiController
{
/**
* @Route("/endpoint", name="api_notification_endpoint", methods={"POST"})
* @param Request $request
* @param NotificationReceiverInterface $notificationManager
* @return JsonResponse
*/
public function handler(Request $request, NotificationReceiverInterface $notificationManager)
{
$notification = $notificationManager->handleRequest($request);
$this->dispatchMessage($notification);
return $this->responseBuilder->setData([])->getResponse();
}
}
<?
class UserNotificationHandler implements MessageHandlerInterface
{
/**
* @var UserRepository
*/
private $userRepository;
/**
* @var ObjectManager
*/
private $entityManager;
/**
* UserNotificationHandler constructor.
* @param UserRepository $userRepository
* @param ObjectManager $entityManager
*/
public function __construct(UserRepository $userRepository, ObjectManager $entityManager)
{
$this->userRepository = $userRepository;
$this->entityManager = $entityManager;
}
public function __invoke(UserNotification $notification)
{
$user = $this->userRepository->findOneBy(['oauthId' => $notification->id]);
if (!$user instanceof User) {
$user = new User();
$user->setOauthId($notification->id);
}
$user
->setFirstName($notification->firstName)
->setLastName($notification->lastName)
->setRoles($notification->roles);
$this->entityManager->persist($user);
$this->entityManager->flush();
}
}
$notificationSender
->setEntityName('order')
->send($order, $id);
bash
composer