bluebaytravel/mandrill

该包已被 弃用,不再维护。没有建议的替代包。

Laravel 5 Mandrill API 包装器

v1.2.0 2017-03-26 19:37 UTC

This package is not auto-updated.

Last update: 2020-01-24 16:02:47 UTC


README

Laravel 5 对 Mandrill API 的包装器,支持多连接。

Build Status StyleCI

// Return the users on the Mandrill account.
Mandrill::users()

// Dependency injection example.
$mandrillManager->users()

安装

使用 Composer,在项目根目录中要求此包。

composer require bluebaytravel/mandrill

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

BlueBayTravel\Mandrill\MandrillServiceProvider::class

如果您想使用 facade,可以在 config/app.php 中添加引用到您的别名数组。

'Mandrill' => BlueBayTravel\Mandrill\Facades\Mandrill::class

配置

Laravel Mandrill 需要连接配置。要开始,您需要发布所有供应商资源

php artisan vendor:publish

这将在您的应用程序中创建一个 config/mandrill.php 文件,您可以修改它来设置配置。同时,请确保检查该包中原始配置文件在版本之间的更改。

默认连接名称

此选项 default 是您可能指定要使用的以下连接之一作为所有工作的默认连接的位置。当然,您可以使用管理类同时使用多个连接。此设置的默认值为 main

Mandrill 连接

此选项 connections 是您为应用程序设置的每个连接的位置。示例配置已包括在内,但您可以添加您想要的任意数量的连接。

用法

Mandrill

Mandrill 类是围绕 mandrill\mandrill 包的包装。

MandrillManager

这是最有兴趣的类。它绑定到 ioc 容器上的 mandrill,并可以使用 Facades\Mandrill facade 访问。该类通过扩展 AbstractManager 实现 ManagerInterface。接口和抽象类都是 Graham Campbell 的 Laravel Manager 包的一部分,因此您可能想要去检查该存储库中管理类的文档。注意,返回的连接类将始终是 BlueBayTravel\Mandrill\Mandrill 的实例。

Facades\Mandrill

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

MandrillServiceProvider

此类没有有趣的公共方法。应将此类添加到 config/app.php 中的提供者数组。此类将设置 ioc 绑定。

示例

在这里,您可以看到这个包如何简单易用。开箱即用,默认适配器是 main。在配置文件中输入您的认证信息后,它就会自动工作

// You can alias this in config/app.php.
use BlueBayTravel\Mandrill\Facades\Mandrill;

Mandrill::users();

Mandrill 管理器将表现得像 BlueBayTravel\Mandrill\Mandrill。如果您想调用特定的连接,可以使用连接方法来实现

use BlueBayTravel\Mandrill\Facades\Mandrill;

// Writing this…
Mandrill::connection('main')->users();

// ...is identical to writing this
Mandrill::users();

// and is also identical to writing this.
Mandrill::connection()->users();

// This is because the main connection is configured to be the default.
Mandrill::getDefaultConnection(); // This will return main.

// We can change the default connection.
Mandrill::setDefaultConnection('alternative'); // The default is now alternative.

如果您像我一样更喜欢使用依赖注入而不是外观,那么您可以注入管理器

use BlueBayTravel\Mandrill\MandrillManager;

class Foo
{
    protected $mandrill;

    public function __construct(MandrillManager $mandrill)
    {
        $this->mandrill = $mandrill;
    }

    public function bar($id)
    {
        $this->mandrill->users();
    }
}

App::make('Foo')->bar();

许可协议

Laravel Mandrill 使用 MIT 许可协议 (MIT) 许可。