artemeon/stream-context

用于创建流上下文的库

0.1.1 2024-09-24 09:52 UTC

This package is auto-updated.

Last update: 2024-09-24 10:09:05 UTC


README

PHP 内部流上下文的接口

描述

包含多个 PHP 流上下文对象,以提供更简单的基于内部包装器的 PHP 上下文选项的接口。提供了一个 FileStream 配置对象,这允许我们透明地更改流,而无需更改客户端类。

入门指南

依赖项

  • 我们使用 https://phpseclib.com/ 来使用基于自定义 StreamWrapper 的 SFTP。
  • 在大多数 PHP 发行版中,SFTP 支持未编译进。

安装

"require": {
  "artemeon/stream-context": "^0.1.0"
}

用法

使用所有 PHP 流感知函数的基本用法

$directory = dir("sftp://ftp.example.com/file.txt", SftpStreamContext::forPasswordAuthentication('password', 'user')->createStreamContext());

使用 FileObjectFactory 和 FileStream 对象的用法

$fileObject = FileObjectFactory::create(FileStream::fromUrl('sftp://test.de/basefolder', SftpStreamContext::forPrivateKeyAuthentication('Aefs566456DG_fgdf')));
$fileObject = FileObjectFactory::create(FileStream::fromUrl('http://test.de/basefolder', HttpStreamContext::forPostUrlencoded(['type' => 'internal'])));

设置多个上下文和 FileStream 选项

$httpContext = HttpStreamContext::forGet();
$httpContext->setTimeout(5.0);

$fileStream = FileStream::fromUrl('http://test.de/basefolder/import.csv', $httpContext);
$fileStream->setMode('r+');
$fileStream->enforceFileExtension('csv');

$file = FileObjectFactory::create($fileStream);

版本历史

  • 0.1.0 初始发布

许可证

本项目采用 MIT 许可证 - 请参阅 LICENSE 文件以获取详细信息