hoyf / pushwoosh
用于 Laravel 的 Pushwoosh 桥接器
Requires
- php: ^5.6.4 || ^7.0
- gomoob/php-pushwoosh: ^1.9
- graham-campbell/manager: ^4.1
- illuminate/contracts: 5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.*
- illuminate/support: 5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.*
Requires (Dev)
- graham-campbell/testbench: ^5.1
- mockery/mockery: ^1.2
- phpunit/phpunit: ^7.1
README
Laravel Pushwoosh 是一个 Laravel 的 Pushwoosh 桥接器,使用了 Gomoob 的 Pushwoosh 包。
// Create a new notification. $notification = Notification::create()->setContent('Hello Jean !'); // Create a request for the '/createMessage' web service. $request = CreateMessageRequest::create()->addNotification($notification); // Send out the notification. $response = $pushwoosh->createMessage($request); // Check if it was sent ok. $response->isOk();
安装
使用 Composer,在项目根目录中安装此包。
composer require hoy/pushwoosh
将服务提供者添加到 config/app.php 中的 providers 数组。
Hoy\Pushwoosh\PushwooshServiceProvider::class
如果您想使用 门面,请将引用添加到 config/app.php 中的别名数组。
'Pushwoosh' => Hoy\Pushwoosh\Facades\Pushwoosh::class
配置
Laravel Pushwoosh 需要连接配置。要开始,您需要发布所有供应商资产
php artisan vendor:publish
这将创建一个 config/pushwoosh.php 文件,您可以在其中修改配置。同时,请确保检查此包中原始配置文件之间的更改。
默认连接名称
此选项 default 是您指定以下哪个连接作为默认连接以用于所有工作的地方。当然,您可以使用许多连接同时使用管理器类。此设置的默认值是 main。
Pushwoosh 连接
此选项 connections 是为您的应用程序设置每个连接的地方。已包含示例配置,但您可以根据需要添加任意数量的连接。
使用方法
PushwooshManager
这是最感兴趣的类。它绑定到 ioc 容器中的 pushwoosh,并可以通过 Facades\Pushwoosh 门面访问。此类通过扩展 AbstractManager 实现 ManagerInterface。接口和抽象类都是 Graham Campbell 的 Laravel Manager 包的一部分,因此您可能想查看该存储库中的文档,了解如何使用管理器类。请注意,返回的连接类始终是 Gomoob\Pushwoosh\Client\Pushwoosh 的实例。
Facades\Pushwoosh
此门面将动态地将静态方法调用传递给 ioc 容器中的 pushwoosh 对象,默认情况下是 PushwooshManager 类。
PushwooshServiceProvider
此类不包含任何感兴趣的公共方法。此类应添加到 config/app.php 中的提供者数组。此类将设置 ioc 绑定。
示例
在这里,您可以看到此包如何简单易用。默认情况下,默认适配器是 main。在配置文件中输入您的身份验证详细信息后,它将正常工作
// You can alias this in config/app.php. use Hoy\Pushwoosh\Facades\Pushwoosh; Pushwoosh::createMessage($request); // We're done here - how easy was that, it just works! Pushwoosh::getApplication(); // This example is simple and there are far more methods available.
Pushwoosh 管理器将表现得像一个 Gomoob\Pushwoosh\Client\Pushwoosh。如果您想调用特定的连接,可以使用连接方法完成
use Hoy\Pushwoosh\Facades\Pushwoosh; // Writing this… Pushwoosh::connection('main')->createMessage($request); // …is identical to writing this Pushwoosh::createMessage($request); // and is also identical to writing this. Pushwoosh::connection()->createMessage($request); // This is because the main connection is configured to be the default. Pushwoosh::getDefaultConnection(); // This will return main. // We can change the default connection. Pushwoosh::setDefaultConnection('alternative'); // The default is now alternative.
如果您像我一样喜欢使用依赖注入而不是门面,则可以注入管理器
use Hoy\Pushwoosh\PushwooshManager; class Foo { protected $pushwoosh; public function __construct(PushwooshManager $pushwoosh) { $this->pushwoosh = $pushwoosh; } public function bar($request) { $this->pushwoosh->createMessage($request); } } App::make('Foo')->bar();
文档
此包中还有其他未在此处记录的类。这是因为在版本之间,此包是 Gomoob 的 Pushwoosh 包 的 Laravel 包装器。
许可
Laravel Pushwoosh 遵循 MIT 许可协议 (MIT) 许可。
