graham-campbell / dropbox
Dropbox 是 Laravel 5 的 Dropbox 桥接器
Requires
- php: >=5.5.9
- dropbox/dropbox-sdk: ^1.1
- graham-campbell/manager: ^2.3
- illuminate/contracts: 5.1.*|5.2.*|5.3.*|5.4.*
- illuminate/support: 5.1.*|5.2.*|5.3.*|5.4.*
Requires (Dev)
- graham-campbell/testbench: ^3.1
- mockery/mockery: ^0.9.4
- phpunit/phpunit: ^4.8|^5.0
This package is auto-updated.
Last update: 2022-02-01 12:34:23 UTC
README
Laravel Dropbox 由 Graham Campbell 创建并维护,是一个 Dropbox 桥接器,用于 Laravel 5。它使用我的 Laravel Manager 包。您可以自由查看 变更日志、发布版本、许可协议 和 贡献指南。
安装
Laravel Dropbox 需要 PHP 5.5+。这个版本只支持 Laravel 5.1、5.2、5.3 或 5.4。
要获取最新版本,只需使用 Composer 引入项目
$ composer require graham-campbell/dropbox
安装完成后,您需要在您的 config/app.php
中注册 GrahamCampbell\Dropbox\DropboxServiceProvider
服务提供者,并可选地别名我们的外观
'Dropbox' => GrahamCampbell\Dropbox\Facades\Dropbox::class,
配置
Laravel Dropbox 需要连接配置。
要开始,您需要发布所有供应商资源
$ php artisan vendor:publish
这将创建一个 config/dropbox.php
文件在您的应用程序中,您可以修改它以设置配置。同时,确保检查在此包的发布之间原始配置文件的变化。
有两个配置选项
默认连接名称
此选项('default'
)是您可能指定以下哪个连接作为默认连接用于所有工作的位置。当然,您可以使用管理类同时使用多个连接。此设置的默认值为 'main'
。
Dropbox 连接
此选项('connections'
)是为您的应用程序设置每个连接的位置。示例配置已包含,但您可以添加尽可能多的连接。
使用方法
DropboxManager
这是最有兴趣的类。它绑定到ioc容器中的'dropbox'
,可以通过Facades\Dropbox
外观来访问。这个类通过扩展AbstractManager
实现了ManagerInterface
接口。该接口和抽象类都是我Laravel Manager包的一部分,所以您可能想要去这个仓库查看如何使用管理类。注意,返回的连接类始终是\Dropbox\Client
的实例。
Facades\Dropbox
这个外观会将静态方法调用动态传递到ioc容器中的'dropbox'
对象,默认情况下是DropboxManager
类。
DropboxServiceProvider
这个类不包含任何有价值的公共方法。这个类应该被添加到config/app.php
中的提供者数组中。这个类将设置ioc绑定。
真实示例
在这里,您可以看到一个使用这个包的示例是多么简单。默认情况下,适配器是main
。在配置文件中输入您的认证详细信息后,它就会正常工作
use GrahamCampbell\Dropbox\Facades\Dropbox; // you can alias this in config/app.php if you like Dropbox::createFolder('foo'); // we're done here - how easy was that, it just works! Dropbox::delete('foo'); // this example is simple, and there are far more methods available
dropbox管理器会表现得像一个\Dropbox\Client
类。如果您想调用特定的连接,可以使用connection
方法
use GrahamCampbell\Dropbox\Facades\Dropbox; // 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 $ref = Dropbox::connection('alternative')->createCopyRef('foo'); // let's copy the file over to the other connection // note that using the connection method here is optional Dropbox::connection('main')->copyFromCopyRef($ref, 'bar');
考虑到这一点,请注意
use GrahamCampbell\Dropbox\Facades\Dropbox; // writing this: Dropbox::connection('main')->createFolder('foo'); // is identical to writing this: Dropbox::createFolder('foo'); // and is also identical to writing this: Dropbox::connection()->createFolder('foo'); // this is because the main connection is configured to be the default Dropbox::getDefaultConnection(); // this will return main // we can change the default connection Dropbox::setDefaultConnection('alternative'); // the default is now alternative
如果您像我一样喜欢使用依赖注入而不是外观,则可以轻松地按如下方式注入管理器
use GrahamCampbell\Dropbox\DropboxManager; use Illuminate\Support\Facades\App; // you probably have this aliased already class Foo { protected $dropbox; public function __construct(DropboxManager $dropbox) { $this->dropbox = $dropbox; } public function bar() { $this->dropbox->createFolder('foo'); } } App::make('Foo')->bar();
有关如何使用我们背后调用的\Dropbox\Client
类的更多信息,请参阅http://dropbox.github.io/dropbox-sdk-php/api-docs/v1.1.x/source-class-Dropbox.Client.html中的文档,以及管理器类在https://github.com/GrahamCampbell/Laravel-Manager#usage。
更多信息
这个包中还有其他一些未在这里记录的类。这是因为它们不是用于公共使用的,而是由这个包内部使用的。
安全
如果您在这个包中发现了安全漏洞,请发送电子邮件到Graham Campbell的邮箱graham@alt-three.com。所有安全漏洞都将得到及时解决。
许可
Laravel Dropbox遵循MIT许可(MIT)。