ak1r0 / flysystem-nuxeo
此包的最新版本(1.0.0)没有提供许可证信息。
Nuxeo 的 Flysystem 适配器
1.0.0
2019-02-25 14:46 UTC
Requires
- php: ^5.4
- league/flysystem: ^1.0
- nuxeo/nuxeo-php-client: ^1.5
- symfony/http-foundation: ^3.4
Suggests
This package is auto-updated.
Last update: 2024-09-15 22:07:00 UTC
README
Nuxeo 的 Flysystem 适配器
待办事项
- 测试单元
- PHP 7 版本
安装
composer require ak1r0/flysystem-nuxeo
用法
初始化
$config = array( 'url' => 'https://host/nuxeo', 'username' => 'root', 'password' => 'root', 'baseRepository' => '/default-domain/workspaces/myWorkspace/' ) $client = new \Nuxeo\Client\Api\NuxeoClient($config['url'], $config['username'], $config['password']); $nuxeoAdapter = new \Ak1r0\Flysystem\Adapter\Nuxeo($client); $nuxeoAdapter->setPathPrefix($config['baseRepository']); $filesystem = new \League\Flysystem\Filesystem($nuxeoAdapter); $filesystem->addPlugin(new \Ak1r0\Flysystem\Plugin\UidResolverPlugin($nuxeoAdapter)); $filesystem->addPlugin(new \Ak1r0\Flysystem\Plugin\MimetypeConverterPlugin($nuxeoAdapter)); $filesystem->addPlugin(new \Ak1r0\Flysystem\Plugin\ConcatenatorPlugin($nuxeoAdapter));
基本功能
// Read $filesystem->read($path): string; // The file content $filesystem->readStream($path): string; // The file content // Write $filesystem->write(string $path, string $content): bool; // Write Stream $handle = fopen($pathToNewContent, 'r'); $filesystem->writeStream(string $path, resource $handle): bool; // Create Dir $filesystem->createDir(string $dirname, \League\Flysystem\Config $config): array; // return ['path' => '/path/to/dir/', 'type' => 'dir']; // Update $filesystem->update(string $path, string $content): bool; // Update Stream $handle = fopen($pathToNewContent, 'r'); $filesystem->updateStream(string $path, resource $handle): bool; // Rename $filesystem->rename(string $path, string $newName): bool; // Copy $filesystem->copy(string $fromPath, string $toPath): bool; // Delete $filesystem->delete(string $path): bool; $filesystem->deleteDir(string $dirPath): bool;
在写操作后获取 UID
$filesystem->getMetadata($path): array; /* return [ 'type' => 'file', // string 'path' => '/path/to/doc/', // string 'dirname' => 'dir', // string 'timestamp' => 123456, // int 'size' => 500, // int 'mimetype' => 'application/pdf', // string 'uid' => 'f4e22103-2540-46e8-8ed6-2a78586bd2e3', // string - only for writes methods ]; */
插件
UidResolverPlugin
Flysystem 使用路径,但 Nuxeo 的一种最佳实践是使用 uids
$uid = 'f4e22103-2540-46e8-8ed6-2a78586bd2e3'; $filesystem->resolveUid(string $uid): string; // return '/path/to/doc/';
MimetypeConverterPlugin
$filesystem->convert(string $path, string $mimeType): array; /* return [ 'type' => 'file', // string 'path' => '/path/to/doc/', // string 'dirname' => 'dir', // string 'timestamp' => 123456, // int 'size' => 500, // int 'mimetype' => 'application/pdf', // string 'contents' => '...' // string the file content ]; */
ConcatenatorPlugin
$filesystem->concatenate(array [$path, $path1, $path2]): array;
对于这种情况,Nuxeo 也实现了一种使用 uids 的更快的方法
$normalisedArray = $filesystem->concatenate(array [$uid, $uid1, $uid2], bool true): array;
两种情况都返回此数组
[ 'type' => 'file', // string 'path' => '/path/to/doc/', // string 'dirname' => 'dir', // string 'timestamp' => 123456, // int 'size' => 500, // int 'mimetype' => 'application/pdf', // string 'contents' => '...' // string the file content ];