bluebaytravel / ftp
Laravel 5 FTP 服务提供者
Requires
- php: >=5.5.9
- illuminate/support: 5.1.*|5.2.*
Requires (Dev)
- graham-campbell/testbench: ~3.0
- phpunit/phpunit: ^4.7.6
This package is not auto-updated.
Last update: 2021-11-13 07:48:07 UTC
README
Laravel 5 对多连接 FTP 的包装器。
// Return the files on the server. Ftp::ls() // Dependency injection example. $ftpManager->ls()
安装
使用 Composer,在项目根目录下要求此包。
composer require bluebaytravel/ftp
将服务提供者添加到 config/app.php
中的 providers
数组。
BlueBayTravel\Ftp\FtpServiceProvider::class
如果您想使用 facade,可以在 config/app.php
中添加引用到您的别名数组。
'Ftp' => BlueBayTravel\Ftp\Facades\Ftp::class
配置
Laravel Ftp 需要连接配置。要开始,您需要发布所有供应商资产
php artisan vendor:publish
这将在您的应用程序中创建一个 config/ftp.php
文件,您可以修改该文件以设置配置。同时,请确保检查此包中原始配置文件在版本之间的更改。
默认连接名称
此选项 default
是您指定以下哪个连接作为您所有工作的默认连接的地方。当然,您可以使用管理器类同时使用许多连接。此设置的默认值为 main
。
FTP 连接
此选项 connections
是为您的应用程序设置每个连接的地方。示例配置已包含在内,但您可以添加您想要的任何数量的连接。
用法
FTP
这是一个围绕原生 ftp_
函数的包装器。
FTPManager
这是最有趣的类。它绑定到 ioc 容器上的 ftp
,可以使用 Facades\Ftp
facade 访问。此类通过扩展 AbstractManager 实现 ManagerInterface。接口和抽象类都是 Graham Campbell 的 Graham Campbell 的 Laravel Manager 包的一部分,因此您可能想查看该存储库中如何使用管理器类的文档。请注意,返回的连接类始终是 BlueBayTravel\Ftp\Ftp
的实例。
Facades\Ftp
此 facade 将静态方法调用动态地传递到 ioc 容器中的 ftp
对象中,默认情况下是 FtpManager
类。
FtpServiceProvider
此类不包含任何感兴趣的公共方法。此类应添加到 config/app.php
中的提供者数组。此类将设置 ioc 绑定。
示例
这里您可以看到一个使用此包有多么简单易懂的示例。默认情况下,适配器为main
。您在配置文件中输入认证信息后,它就会自动工作。
// You can alias this in config/app.php. use BlueBayTravel\Ftp\Facades\Ftp; Ftp::users();
Ftp管理器将表现得像一个BlueBayTravel\Ftp\Ftp
。如果您想要调用特定连接,可以通过连接方法实现。
use BlueBayTravel\Ftp\Facades\Ftp; // Writing this… Ftp::connection('main')->ls(); // ...is identical to writing this Ftp::ls(); // and is also identical to writing this. Ftp::connection()->ls(); // This is because the main connection is configured to be the default. Ftp::getDefaultConnection(); // This will return main. // We can change the default connection. Ftp::setDefaultConnection('alternative'); // The default is now alternative.
如果您像我一样偏好使用依赖注入而非外观(facade),则可以注入管理器。
use BlueBayTravel\Ftp\FtpManager; class Foo { protected $ftp; public function __construct(FtpManager $ftp) { $this->ftp = $ftp; } public function bar($id) { $this->ftp->ls(); } } App::make('ftp')->ls();
许可证
FTP遵循MIT许可证(MIT)。