Skip to content

EvilDevRu/PhpSms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PHP sms client

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages