compenda / sendwithus
SendWithUs 是 Laravel 5 的 SendWithUs 桥接器
Requires
- php: >=5.5.9
- graham-campbell/manager: ^2.3
- illuminate/contracts: 5.1.*|5.2.*
- illuminate/support: 5.1.*|5.2.*
- sendwithus/api: ^2.12.1
Requires (Dev)
- mockery/mockery: ^0.9.4
- phpunit/phpunit: ^4.8|^5.0
This package is not auto-updated.
Last update: 2020-01-24 16:59:47 UTC
README
一个用于与 sendwithus_php 一起使用 Laravel 5 的包
此存储库源自 Graham Campbell 的 Laravel-Dropbox
安装
需要 PHP 5.5+ 或 HHVM 3.6+。
要获取 Laravel SendWithUs 的最新版本,只需使用 Composer 请求项目
$ composer require compenda/sendwithus
当然,您也可以手动更新 require 块并运行 composer update
{
"require": {
"compenda/sendwithus": "^0.1.0"
}
}
安装 Laravel SendWithUs 后,您需要注册服务提供者。打开 config/app.php 并将以下内容添加到 providers 键中。
'Compenda\SendWithUs\SendWithUsServiceProvider'
您可以在 config/app.php 文件的 aliases 键中注册 SendWithUs 门面。
'SendWithUs' => 'Compenda\SendWithUs\Facades\SendWithUs'
配置
Laravel Sendwithus 需要连接配置。
要开始,您需要发布所有供应商资产
$ php artisan vendor:publish
这将在您的应用中创建一个 config/sendwithus.php 文件,您可以修改它以设置配置。同时,请确保检查此包中原始配置文件之间的更改。
有两个配置选项
默认连接名称
此选项('default')是您指定以下哪个连接作为您所有工作的默认连接的地方。当然,您可以使用管理类同时使用多个连接。此设置的默认值为 'main'。
SendWithUs 连接
此选项('connections')是为您的应用程序设置每个连接的地方。已包含示例配置,但您可以添加任意多的连接。
用法
SendWithUsManager
这是最感兴趣的类。它绑定到 ioc 容器上的 'sendwithus',并可以通过 Facades\SendWithUs 门面访问。此类通过扩展 AbstractManager 实现 ManagerInterface。接口和抽象类都是我的 Laravel Manager 包的一部分,因此您可能想查看 那个存储库 中的文档,了解如何使用管理类。请注意,返回的连接类始终是 \sendwithus\API 的实例。
Facades\SendWithUs
此门面将动态地将静态方法调用传递到 ioc 容器中的 'sendwithus' 对象,默认情况下是 SendWithUsManager 类。
SendWithUsServiceProvider
这个类不包含任何有趣的公共方法。这个类应该被添加到 config/app.php 中的 providers 数组。这个类将设置 ioc 绑定。
实际示例
在这里,你可以看到一个示例,说明这个包有多么简单易用。默认情况下,默认适配器是 main。在配置文件中输入您的认证信息后,它就会正常工作。
use Compenda\SendWithUs\Facades\SendWithUs; // you can alias this in config/app.php if you like $emails = SendWithUs::emails(); // we're done here - how easy was that, it just works! $segments = SendWithUs::get_segments(); // this example is simple, and there are far more methods available
sendwithus 管理器将表现得像是一个 \sendwithus\API 类。如果您想调用特定的连接,可以使用 connection 方法。
use Compenda\SendWithUs\Facades\SendWithUs; // the alternative connection is the other example provided in the default config // let's create a copy ref so we can copy a file to the main connection $emails = SendWithUs::connection('alternative')->emails();
考虑到这一点,请注意:
use Compenda\SendWithUs\Facades\SendWithUs; // writing this: $emails = SendWithUs::connection('main')->emails(); // is identical to writing this: $emails = SendWithUs::emails(); // and is also identical to writing this: $emails = SendWithUs::connection('main')->emails(); // this is because the main connection is configured to be the default SendWithUs::getDefaultConnection(); // this will return main // we can change the default connection SendWithUs::setDefaultConnection('alternative'); // the default is now alternative
如果您更喜欢使用依赖注入而不是外观(facade),则可以像这样轻松地注入管理器:
use Compenda\SendWithUs\SendWithUsManager; use Illuminate\Support\Facades\App; // you probably have this aliased already class Foo { protected $sendwithus; public function __construct(SendWithUsManager $sendwithus) { $this->sendwithus = $sendwithus; } public function bar() { return $this->sendwithus->emails(); } } App::make('Foo')->bar();
有关如何使用我们在此后台调用的 \sendwithus\API 类的更多信息,请查看以下仓库:https://github.com/sendwithus/sendwithus_php,以及管理器类在 https://github.com/GrahamCampbell/Laravel-Manager#usage。
更多信息
这个包中还有一些其他类没有在此处进行文档记录。这是因为它们不是用于公共使用的,而是由这个包内部使用的。
许可
Laravel-SendWithUs 在 MIT 许可证 (MIT) 下授权。