zoo/pushwoosh

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

Laravel Pushwoosh 桥接器

2.2.0 2016-07-11 19:13 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:47:14 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) 许可。