evildevru/php-sms

Simple client for send sms messages.

Installs: 11

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:extension

v1.0.0 2023-01-17 06:31 UTC

This package is auto-updated.

Last update: 2024-04-17 09:24:22 UTC


README

PHP Client for send sms messages via DI.

Install

composer require evildevru/php-sms

Requirements

  • PHP >= 8.0

Setting up Yii2

yii2 configure file

'container' => [
    'singletons' => [
        SmsInterface::class => static function () {
            return new SmsRu($_ENV['SMS_API_KEY'], new SmsClient([
                'base_uri' => 'https://sms.ru',
            ]));
        },
    ],
],

for example controller

    /**
     * @var SmsInterface
     */
    protected SmsInterface $sms;

    /**
     * @param SmsInterface $sms
     */
    public function __construct(SmsInterface $sms) 
    {
        $this->sms = $sms;
    }

    /**
     * @return void
     */
    public function actionIndex(?string $phone): void
    {
        $response = $this->sms->send($phone, 'wake up');
        if (!$response->isSuccess()) {
            throw new RuntimeException();
        }
    }

Supported services

  • sms.ru

You can extend this list.

Licence

MIT