schimpanz/pushwoosh

此包已被废弃且不再维护。作者建议使用 hoy/pushwoosh 包。

Pushwoosh 的 Laravel 桥接器

2.2.0 2016-07-11 19:13 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:49:36 UTC


README

pushwoosh

Laravel Pushwoosh 是一个使用 Pushwoosh 的 Laravel 桥接器,基于 GomoobPushwoosh 包

// 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) 下授权。