lechimp-p / flightcontrol
用于在Leagues flysystem目录中迭代和递归的接口。
1.0.0
2021-05-16 18:28 UTC
Requires
- php: >=7.3
- league/flysystem: ^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- league/flysystem-memory: ^2.0
- league/flysystem-ziparchive: ^2.0
- phpunit/phpunit: ^9.5
README
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::toDirectory
或FSObject::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
给出目录中文件系统对象的列表。