2017 © Pedro Peláez
 

library yii2-message-delivery

Message Delivery Yii2 Implementation

image

wearesho-team/yii2-message-delivery

Message Delivery Yii2 Implementation

  • Thursday, June 28, 2018
  • by Horat1us
  • Repository
  • 3 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 12 Versions
  • 0 % Grown

The README.md

Yii2 Message Delivery

Test & Lint Latest Stable Version Total Downloads codecov, (*1)

This repository includes RepositoryInterface implementation using Yii2 ActiveRecord, (*2)

Installation

composer require wearesho-team/yii2-message-delivery:^1.8.0

Usage

Configuration

<?php
// common/config/main.php

use Wearesho\Delivery;

return [
    'bootstrap' => [
        Delivery\Yii2\Bootstrap::class, // registers migrations and configures container        
    ],
];

Queue

This package provides optional yii2-queue integration. To use it you have to install yii2-queue package:, (*3)

composer require yiisoft/yii2-queue:^2.0

Then you may configure your application:, (*4)

<?php
// common/config/main.php

use Wearesho\Delivery;

return [
    'bootstrap' => [
        [
            'class' => Delivery\Yii2\Bootstrap::class,
            'service' => [
                'class' => Delivery\Yii2\Queue\Service::class,
                'service' => Delivery\ServiceMock::class, // you your custom Delivery\ServiceInterface implementation
            ],
        ],
    ],
];

Note: messages sent using Queue\Service have to correct work with serialize() and unserialize(). See yii2-queue for details, (*5)

Skipping queue while sending message

Sometimes there is need to send message without queue (for example during mass messaging in CLI environment). To skip queue service you need to create message with options (Delivery\MessageOptionsInterface):, (*6)

<?php

use Wearesho\Delivery;

/** @var Delivery\Yii2\Queue\Service $service */
$message = new Delivery\MessageWithOptions(
    recipient: '380930000000',
    text: 'Message Text',
    options: [
        Delivery\Yii2\Queue\Service::OPTION_SYNC => true,  
    ]
);

$service->send($message); // message will be sent directly to sync service without queue job

SwitchService

You can configure few delivery services, and choose one of them using environment variable., (*7)

<?php

use Wearesho\Delivery;
use App;

$service = new Delivery\Yii2\SwitchService([
    'environmentKeyPrefix' => 'DELIVERY_', // by default,
    'services' => [
        'default' => [
            'class' => Delivery\ServiceMock::class,
        ],
        'production' => [
            'class' => App\Delivery\Service::class, // some Delivery\ServiceInterface implementation
        ],
    ],
]);

putenv('DELIVERY_SERVICE'); // clean environment
$message = new Delivery\Message('text', 'recipient');
$service->send($message); // default service will be used if no environment variable set
putenv('DELIVERY_SERVICE=production');
$service->send($message); // production service will be used if it was configured

RepositoryService

You can wrap any your service into RepositoryService, that has repository. If sending message in wrapped service did not throwed any exception message will be stored as sent., (*8)

<?php

use Wearesho\Delivery;
use App;

$service = new Delivery\Yii2\RepositoryService([
    'service' => App\CustomService::class,
    'repository' => Delivery\Yii2\Repository::class, // or your own implementation
]);

// do what you want using Delivery\ServiceInterface

Authors

License

MIT, (*9)

The Versions

28/06 2018
21/05 2018

dev-feature/sender-name-in-job

dev-feature/sender-name-in-job

Message Delivery Yii2 Implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Letnikow

21/05 2018

dev-feature/repository-service

dev-feature/repository-service

Message Delivery Yii2 Implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Letnikow

18/05 2018

dev-feature/switch-service

dev-feature/switch-service

Message Delivery Yii2 Implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Letnikow

16/05 2018

1.2.0

1.2.0.0

Message Delivery Yii2 Implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Letnikow

16/05 2018

dev-feature/serialization-refactor

dev-feature/serialization-refactor

Message Delivery Yii2 Implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Letnikow

15/05 2018

1.1.0

1.1.0.0

Message Delivery Yii2 Implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Letnikow

15/05 2018

1.0.0

1.0.0.0

Message Delivery Yii2 Implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Letnikow