hoy/pushwoosh

Laravel 的 Pushwoosh 桥接器

此包的官方仓库似乎已不存在,因此该包已被冻结。

2.2.0 2016-07-11 19:13 UTC

This package is not auto-updated.

Last update: 2022-06-11 06:11:16 UTC


README

pushwoosh

Laravel Pushwoosh 是一个使用 PushwooshGomoobPushwoosh 包 的 Laravel 桥接器。

// 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();

Build Status StyleCI Coverage Status Quality Score Latest Version License

安装

使用 Composer 在项目根目录中安装此包。

composer require hoy/pushwoosh

将服务提供者添加到 config/app.php 中的 providers 数组。

Hoy\Pushwoosh\PushwooshServiceProvider::class

如果您想使用 facade,可以在 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 facade 访问。此类通过扩展 AbstractManager 实现 ManagerInterface。接口和抽象类都是 Graham Campbell 的 Laravel Manager 包的一部分,因此您可能想查看该存储库的文档,了解如何使用管理器类。请注意,返回的连接类始终是 Gomoob\Pushwoosh\Client\Pushwoosh 的实例。

Facades\Pushwoosh

此 facade 将动态地将静态方法调用传递到 ioc 容器中的 pushwoosh 对象,默认情况下是 PushwooshManager 类。

PushwooshServiceProvider

这个类不包含任何感兴趣的公共方法。应该将这个类添加到config/app.php中的providers数组中。这个类将设置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();

文档

这个包中还有其他未在此处记录的类。这是因为该包是GomoobPushwoosh包的Laravel包装器。

许可协议

Laravel Pushwoosh遵循MIT许可协议(MIT)