wearesho-team / yii2-message-delivery
Message Delivery Yii2 Implementation
2.1.0
2024-11-12 16:31 UTC
Requires
- php: ^8.1
- horat1us/environment-config: ^1.2
- horat1us/yii2-carbon-behavior: ^1.2
- horat1us/yii2-migration-bootstrap: ^1.3
- horat1us/yii2-validation-exception: ^1.1
- nesbot/carbon: ^2.24 || ^3
- wearesho-team/message-delivery: ^1.9
- yiisoft/yii2: ^2.0.47
Requires (Dev)
- ext-json: *
- horat1us/yii2-asset-free: ^1.0
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.7
- yiisoft/yii2-queue: ^2.0
Suggests
- yiisoft/yii2-queue: Need for Delivery\Yii\Queue\Service
This package is auto-updated.
Last update: 2024-11-12 16:32:09 UTC
README
This repository includes RepositoryInterface implementation using Yii2 ActiveRecord
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:
composer require yiisoft/yii2-queue:^2.0
Then you may configure your application:
<?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
SwitchService
You can configure few delivery services, and choose one of them using environment variable.
<?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.
<?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