mingalevme/onesignal
Composer 安装命令:
composer require mingalevme/onesignal
包简介
Simple OneSignal PHP Client
关键字:
README 文档
README
Really simple and well tested OneSignal client (creating notifications only) with PSR-only dependencies:
- PHP 7.4+
- PSR-17: HTTP Factories
- PSR-18: HTTP Client
- JSON-extension (as of PHP 8.0.0, the JSON-extension is a core PHP extension, so it is always available)
More about code quality:
- 95%+ of code are covered with tests
- project uses Psalm and PHPStan at max levels
composer auditon every commit by CI/CD- PHP_CodeSniffer
Composer
composer require mingalevme/onesignal:^2.0.0-alpha
Examples
Example (DI Container)
Set up some DI container somewhere like Application-level service provider:
<?php declare(strict_types=1); use Mingalevme\OneSignal\ClientFactory; use Mingalevme\OneSignal\ClientFactoryInterface; use Mingalevme\OneSignal\ClientInterface; use Mingalevme\OneSignal\CreateClientOptions; class AppServiceProvider { public function register(SomeConfigClass $someConfig, SomeDIContainerClass $container): void { // ... /** @var string $appId */ $appId = $someConfig->get('onesignal-app-id'); /** @var string $restApiKey */ $restApiKey = $someConfig->get('my-rest-api-key'); $container->set(ClientFactoryInterface::class, ClientFactory::class); $container->set( ClientInterface::class, fn() => $container->get(ClientFactoryInterface::class) ->create(CreateClientOptions::new($appId, $restAPIKey)) ); // ... } }
Some application logic
Note It's recommended to use some app-level interface for notification sender, e.g.
MyAppNotificationSenderInterface, instead ofClientInterface/CreateNotificationInterface.
<?php declare(strict_types=1); use Mingalevme\OneSignal\ClientInterface; use Mingalevme\OneSignal\CreateNotificationOptions; use Mingalevme\OneSignal\Notification\PushNotification; class NotifySubscribersOnPostCreatedEventHandler { private SubscribersRespo $repo; private ClientInterface $client; public function __construct(SubscribersRepo $repo, ClientInterface $client) { $this->repo = $repo; $this->client = $client; } public function handle(PostCreatedEvent $event): void { $post = $event->getPost(); /** @var string[] $subscriberIds */ $subscriberIds = $this->repo->getSubscriberIdsOfAuthor($post->getAuthorId()); $notification = PushNotification::createContentsNotification($post->getTitle()) ->setHeadings($post->getAuthorDisplayName()) ->setData([ 'post_id' => $post->getId(), ]) ->setExternalId("post-{$post->getId()}") ->setIncludeExternalUserIds($subscriberIds); $this->client->createNotification($notification); } }
Example (Inline)
<?php declare(strict_types=1); use GuzzleHttp\Psr7\HttpFactory; use Mingalevme\OneSignal\Client; use Mingalevme\OneSignal\CreateClientOptions; use Mingalevme\OneSignal\CreateNotificationOptions; use Mingalevme\OneSignal\Notification\PushNotification; $appId = 'my-app-id'; $restApiKey = 'my-rest-api-key'; $psrHttpClient = new \GuzzleHttp\Client(); $psr7Factory = new HttpFactory(); $client = new Client(CreateClientOptions::new($appId, $restAPIKey), $psrHttpClient, $psr7Factory, $psr7Factory); $notification = PushNotification::createContentsNotification('text') ->setData([ 'type' => 'my-notification-type', 'data' => 'some-extra-data', ]) ->addFilterTagExists('tag1') ->addFilterTag('tag2', '>', 'value2') ->setSmallIcon('push_icon') ->setTtl(3600 * 3) ->setIosCategory('my-ios-category') ->setExternalId('custom-notification-id'); $result = $client->createNotification($notification); echo <<<END Notification has been successfully sent to OneSignal: #{$result->getNotificationId()}. END;
Quality (OSX)
Install PHP 7.4+
brew install php@7.4 /usr/local/opt/php@7.4/bin/pecl install xdebug
Composer
brew install composer /usr/local/opt/php@7.4/bin/php /usr/local/bin/composer install
PHPUnit
/usr/local/opt/php@7.4/bin/php vendor/bin/phpunit
Psalm
/usr/local/opt/php@7.4/bin/php vendor/bin/psalm
PHPStan
/usr/local/opt/php@7.4/bin/php vendor/bin/phpstan analyse
PHP_CodeSniffer
/usr/local/opt/php@7.4/bin/php vendor/bin/phpcs
mingalevme/onesignal 适用场景与选型建议
mingalevme/onesignal 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.07k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 11 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「onesignal」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mingalevme/onesignal 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mingalevme/onesignal 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mingalevme/onesignal 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
OneSignal REST API Wrapper For Laravel/Lumen
Symfony bundle to sent push notifications through various providers
Symfony OneSignal Api Bundle
Laravel OneSignal Notification
This is a restful api to onesignal.
Adds Web Push notification feature to flarum with OneSignal service
统计信息
- 总下载量: 2.07k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-11-09