2017 © Pedro Peláez
 

symfony-bundle push-notification-bundle

Symfony2 bundle for sending push notifications with OneSignal

image

dmytrof/push-notification-bundle

Symfony2 bundle for sending push notifications with OneSignal

  • Friday, August 25, 2017
  • by dmytrof
  • Repository
  • 1 Watchers
  • 0 Stars
  • 208 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 9 Versions
  • 0 % Grown

The README.md

PushNotificationBundle

Symfony2 bundle for sending push notifications with OneSignal, (*1)

Installation

Step 1: Composer require

$ php composer.phar require "norkunas/onesignal-php-api":"1.0.x-dev" "dmytrof/push-notification-bundle"

Step2: Enable the bundle in the kernel

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Dmytrof\PushNotificationBundle\DmytrofPushNotificationBundle(),
        // ...
    );
}

Configuration

Enable the bundle in your config.yml:, (*2)

# app/config/config.yml
dmytrof_push_notification:
    provider: one_signal
    one_signal:                                                 # See: https://documentation.onesignal.com/docs/web-push-sdk-setup-http
        app_id: "%one_signal.app_id%"
        app_auth_key: "%one_signal.auth_key%"
        safari_web_id: "%one_signal.safari_web_id%"     # Safari Support (Optional). See: https://documentation.onesignal.com/docs/web-push-sdk-setup-http#section-3-safari-support-optional-
        subdomain: "%one_signal.subdomain%"             # HTTP Setup ONLY. See https://documentation.onesignal.com/docs/web-push-sdk-setup-http#section-1-4-choose-subdomain

Usage

Web Push SDK Setup

{# layout.html.twig #}
<head>
{# ... #}

{{ dmytrof_push_notification_web_sdk() }}
</head>

Tag your users

<?php
// SomeController

public function addTagAction()
{
    // ...

    $this->get('dmytrof_push_notification.provider')->addTag('tagName', 'tagValue');

    // ...
}

public function addTagsAction()
{
    // ...

    $this->get('dmytrof_push_notification.provider')->addTags([
        'tagName1' => 'value1',
        'tagName2' => 'value2'
    ]);

    // ...
}

Users will be tagged after rendering of layout with Web Push SDK, (*3)

Remove tags

<?php
// SomeController

public function removeTagsAction()
{
    // ...

    $this->get('dmytrof_push_notification.provider')->removeTags([
        'tagName1',
        'tagName2'
    ]);

    // ...
}

Tags will be removed after rendering of layout with Web Push SDK, (*4)

Send Push Notification

<?php
// SomeController

public function sendNotificationAction()
{
    // Send to all

    $provider = $this->get('dmytrof_push_notification.provider');
    $notification = $provider->createNotification()
                                ->setSubject('Notification Subject')
                                ->setMessage('Test notification for all')
                                ->includeSegments(['All']);

    $provider->sendNotification($notification);


    // Filter by tags

    $notification = $provider->createNotification()
                                ->setSubject('Notification Subject')
                                ->setMessage('Filtered by tags')
                                ->filterByTag('tagName1', '=', 'value1')
                                ->filterByTag('tagName2', '=', 'value2', true);
    $provider->sendNotification($notification);


    // Send templated message to user

    $notification = $provider->createNotification()
                                ->setTemplate('AppBundle:PushNotification:test_notification.html.twig', [
                                    'user' => $user
                                ])
                                ->filterByTag('userId', '=', $user->getId());
    $provider->sendNotification($notification);
}

Configure message template:, (*5)

{# 'AppBundle:PushNotification:test_notification.html.twig' #}
{% extends 'DmytrofPushNotificationBundle:PushNotification:layout.html.twig' %}

{% block Subject %}
    Test templated subject
{% endblock %}

{% block Message %}
    Your user ID: {{ user.id }}
{% endblock %}

{% block Url %}
    {{ absolute_url(path('YOUR_ROUTE')) }}
{% endblock %}

The Versions

25/08 2017

dev-master

9999999-dev

Symfony2 bundle for sending push notifications with OneSignal

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmytro Feshchenko

25/08 2017

0.2.2

0.2.2.0

Symfony2 bundle for sending push notifications with OneSignal

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmytro Feshchenko

25/08 2017

0.2.1

0.2.1.0

Symfony2 bundle for sending push notifications with OneSignal

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmytro Feshchenko

13/01 2017

0.2

0.2.0.0

Symfony2 bundle for sending push notifications with OneSignal

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmytro Feshchenko

29/12 2016

0.1.4

0.1.4.0

Symfony2 bundle for sending push notifications with OneSignal

  Sources   Download

MIT

The Requires

 

by Dmytro Feshchenko

29/12 2016

0.1.3

0.1.3.0

Symfony2 bundle for sending push notifications with OneSignal

  Sources   Download

MIT

The Requires

 

by Dmytro Feshchenko

29/12 2016

0.1.2

0.1.2.0

Symfony2 bundle for sending push notifications with OneSignal

  Sources   Download

MIT

The Requires

 

by Dmytro Feshchenko

29/12 2016

0.1.1

0.1.1.0

Symfony2 bundle for sending push notifications with OneSignal

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmytro Feshchenko

29/12 2016

0.1

0.1.0.0

Symfony2 bundle for sending push notifications with OneSignal

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmytro Feshchenko