wearesho-team / yii2-message-delivery
Message Delivery Yii2 Implementation
Package info
github.com/wearesho-team/yii2-message-delivery
pkg:composer/wearesho-team/yii2-message-delivery
Requires
- php: >=8.4
- horat1us/environment-config: ^1.6
- horat1us/yii2-carbon-behavior: ^1.4
- horat1us/yii2-environment-config: ^1.2
- horat1us/yii2-migration-bootstrap: ^1.4
- horat1us/yii2-validation-exception: ^1.2
- nesbot/carbon: ^3.2 || ^2.73
- wearesho-team/message-delivery: ^2.3
- yiisoft/yii2: ^2.0.54
Requires (Dev)
- ext-json: *
- horat1us/yii2-asset-free: ^1.1
- phpunit/phpunit: ^13.4
- squizlabs/php_codesniffer: ^4.0
- yiisoft/yii2-queue: ^2.3.8
Suggests
- yiisoft/yii2-queue: Need for Delivery\Yii\Queue\Service
Provides
None
Conflicts
None
Replaces
None
- dev-master
- 3.2.0
- 3.1.0
- 3.0.1
- 3.0.0
- 3.0.0-beta.16
- 3.0.0-beta.15
- 3.0.0-beta.14
- 3.0.0-beta.13
- 3.0.0-beta.12
- 3.0.0-beta.11
- 3.0.0-beta.10
- 3.0.0-beta.9
- 3.0.0-beta.8
- 3.0.0-beta.7
- 3.0.0-beta.6
- 3.0.0-beta.5
- 3.0.0-beta.4
- 3.0.0-beta.3
- 3.0.0-beta.2
- 3.0.0-beta.1
- 2.2.0
- 2.1.0
- 2.0.0
- 1.10.2
- 1.10.1
- 1.10.0
- 1.9.0
- 1.8.0
- 1.7.0
- 1.6.0
- 1.5.0
- 1.4.0
- 1.3.0
- 1.2.0
- 1.1.0
- 1.0.0
- dev-php-8.4
- dev-release/3
- dev-feature/switch-service
- dev-feature/prepare-php7.3
- dev-feature/serialization-refactor
This package is auto-updated.
Last update: 2026-10-26 15:14:10 UTC
README
This repository includes History\RepositoryInterface implementation using Yii2 ActiveRecord
Compatibility: tested on PHP 8.4, PHP 8.5
Installation
composer require wearesho-team/yii2-message-delivery:^3.2
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.3.8
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\StubService::class, // your custom Delivery\ServiceInterface implementation ], ], ], ];
Note: messages sent using Queue\Service have to correct work with serialize() and unserialize(). See yii2-queue for details
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 the Delivery\Yii2\Queue\Options::SYNC option:
<?php use Wearesho\Delivery; /** @var Delivery\Yii2\Queue\Service $service */ $message = new Delivery\Message( text: 'Message Text', recipient: '380930000000', options: [ Delivery\Yii2\Queue\Options::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.
<?php use Wearesho\Delivery; use App; $service = new Delivery\Yii2\SwitchService([ 'config' => [ 'class' => Delivery\Yii2\SwitchService\EnvironmentConfig::class, 'keyPrefix' => 'DELIVERY_', // by default ], 'services' => [ 'default' => [ 'class' => Delivery\StubService::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
History
To store the results of sent messages, wrap your service into Delivery\History\Service
(from wearesho-team/message-delivery)
with this package's repository:
<?php use Wearesho\Delivery; use App; $service = new Delivery\History\Service( baseService: Delivery\Batch\Service::wrap(new App\CustomService()), repository: new Delivery\Yii2\Repository(), // or your own implementation ); // do what you want using Delivery\Batch\ServiceInterface