2017 © Pedro Peláez
 

cakephp-plugin cakephp-notifier

CvoTechnologies/Notifier plugin for CakePHP

image

cvo-technologies/cakephp-notifier

CvoTechnologies/Notifier plugin for CakePHP

  • Monday, August 8, 2016
  • by Marlinc
  • Repository
  • 1 Watchers
  • 1 Stars
  • 127 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

CvoTechnologies/Notifier plugin for CakePHP

Software License Build Status Coverage Status Total Downloads Latest Stable Version, (*1)

Usage

Configuring notifications transports

Add the following section to your application config in app.php., (*2)

    'NotificationTransport' => [
        'email' => [
            'className' => 'CvoTechnologies/Notifier.Email',
            'profile' => 'default',
        ],
        'irc' => [
            'className' => 'Irc',
            'channel' => '#cvo-technlogies'
        ],
        'twitter' => [
            'className' => 'CvoTechnologies/Twitter.Twitter',
        ],
        'example' => [
            'className' => 'Example',
            'someOption' => true
        ]
    ],

Creating a notifier

namespace App\Notifier;

use CvoTechnologies\Notifier\Notifier;

class UserNotifier extends Notifier
{
    public function welcome($user)
    {
        $this
            ->to([
                'irc' => $user->irc_nickname,
                'twitter' => $user->twitter_nickname
            ])
            ->subject(sprintf('Welcome %s', $user->name))
            ->template('welcome_message') // By default template with same name as method name is used.
            ->viewVars([
                'user' => $user
            ])
            ->transports([
                'irc',
                'twitter'
            ]);
    }
}

Creating notification template

Create a template file in Template/Notification/transport-type. This will be used as template for the notification., (*3)

For example: Template/Notification/irc/welcome.ctp, (*4)

Welcome <?= $user->name; ?> to our website!

Using it

Using the notifier is very easy. Here's an example on how to use it in a controller:, (*5)

namespace App\Controller;

use CvoTechnologies\Notifier\NotifierAwareTrait;

class UsersController extends AppController
{
    use NotifierAwareTrait;

    public function register()
    {
        $user = $this->Users->newEntity();
        if ($this->request->is('post')) {
            $user = $this->Users->patchEntity($user, $this->request->data())
            if ($this->Users->save($user)) {
                $this->getNotifier('User')->send('welcome', [$user]);
            }
        }
        $this->set('user', $user);
    }
}

Creating a transport

A transport is used to talk to a particular service., (*6)

It can accept configuration options that are passed from the NotificationTransport section in your application config., (*7)

<?php

namespace App\Notifier\Transport;

use CvoTechnologies\Notifier\AbstractTransport;

class ExampleTransport extends AbstractTransport
{
    const TYPE = 'example';

    /**
     * Send notification.
     *
     * @param \CvoTechnologies\Notifier\Notification $notification Notification instance.
     * @return array
     */
    public function send(Notification $notification)
    {
        // Send notificaiton
        $result = NotificationSendingService::send($notification->message(static::TYPE));

        return (array)$result;
    }
}

The Versions

08/08 2016

dev-master

9999999-dev

CvoTechnologies/Notifier plugin for CakePHP

  Sources   Download

MIT

The Requires

 

The Development Requires

08/08 2016

1.0.0

1.0.0.0

CvoTechnologies/Notifier plugin for CakePHP

  Sources   Download

MIT

The Requires

 

The Development Requires