PHP code example of cvo-technologies / cakephp-notifier

1. Go to this page and download the library: Download cvo-technologies/cakephp-notifier 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/ */

    

cvo-technologies / cakephp-notifier example snippets


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

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'
            ]);
    }
}

Welcome <?= $user->name; 

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



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