lechimp-p/flightcontrol

用于在Leagues flysystem目录中迭代和递归的接口。

1.0.0 2021-05-16 18:28 UTC

This package is auto-updated.

Last update: 2024-09-22 22:06:26 UTC


README

Build Status Scrutinizer Coverage

Flightcontrol

Leagues flysystem 中迭代和递归的接口。

此README.md 也是一个可读的PHP文件。

此代码在GPLv3许可证下发布。

用法

初始化

flightcontrol是在flysystem上初始化的,例如

<?php

require_once("vendor/autoload.php");

use \League\Flysystem\Adapter\Local;
use \League\Flysystem\Filesystem;
use \Lechimp\Flightcontrol\Flightcontrol;

$adapter = new Local(__DIR__, LOCK_EX, Local::SKIP_LINKS);
$flysystem = new Filesystem($adapter);

$flightcontrol = new Flightcontrol($flysystem);

?>

确保在使用flightcontrol时使用Local::SKIP_LINKS选项,因为它只会处理文件和目录。

文件系统对象

flightcontrol可以给你flystem的对象

<?php

// base directory from the flysystem:
$root = $flightcontrol->get("/");
assert($root !== null);
assert($root instanceof \Lechimp\Flightcontrol\FSObject);

// the tests directory:
$tests = $flightcontrol->directory("/tests");
assert($tests !== null);
assert($tests instanceof \Lechimp\Flightcontrol\Directory);

// this file:
$readme = $flightcontrol->file("/README.md");  
assert($readme !== null);
assert($readme instanceof \Lechimp\Flightcontrol\File);

?>

注意,您可以使用Flightcontrol::get来获取目录或文件,使用Flightcontrol::directory来获取目录,或使用Flightcontrol::file来获取文件。这些获取器在没有在flysystem中找到匹配对象时将返回null。

您还可以使用FSObject::toDirectoryFSObject::toFile将FSObject强制转换为文件或目录,如果您得到一个null,则对象不是您想要的。

文件系统对象的属性

flightcontrol返回的对象有不同的属性

<?php

// properties of every filesystem object:
echo '$tests->path() == '.$tests->path()."\n";
assert($tests->path() == "/tests");
echo '$tests->name() == '.$tests->name()."\n";
assert($tests->name() == "tests");

// properties of files:
echo '$readme->timestamp() == '.$readme->timestamp()."\n";
assert(is_string($readme->timestamp()) || is_int($readme->timestamp()));
echo '$readme->mimetype() == '.$readme->mimetype()."\n";
assert($readme->mimetype() == "text/plain");
echo '$readme->content()'."\n";
assert(is_string($readme->content()));

// properties of directories:
$contents = $tests->contents();
echo '$tests->contents()'."\n";
assert(count($contents) > 0);
assert($contents[0] instanceof \Lechimp\Flightcontrol\FSObject);

?>

File::content返回文件的字符串内容。Directory::contents给出目录中文件系统对象的列表。