PHP code example of wearesho-team / yii2-message-delivery

1. Go to this page and download the library: Download wearesho-team/yii2-message-delivery 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/ */

    

wearesho-team / yii2-message-delivery example snippets



// common/config/main.php

use Wearesho\Delivery;

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


// 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
            ],
        ],
    ],
];



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



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




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