danjones000 / php-xattr
用于访问和修改文件扩展属性的简单模块
v0.3.0
2021-03-10 22:00 UTC
This package is auto-updated.
Last update: 2024-09-11 05:20:41 UTC
README
此库旨在访问和操作文件的扩展属性。
这可能只适用于Linux,并且必须正确设置所有配置才能使其工作。
理想情况下,您应该安装xattr 扩展。如果您没有安装,我们将尝试使用 attr
命令。
此库设计为静默失败。这意味着如果既没有安装 xattr 扩展,也没有 attr 命令可用,它将什么也不做。如果文件系统不支持扩展属性,也会发生这种情况。
安装
composer require danjones000/php-xattr
使用方法
use Danjones\Xattr\Xattr;
use Danjones\Xattr\File;
$file = 'path/to/file';
$xattr = new Xattr();
$attributes = $xattr->list($file); // Returns array of attribute names, without values
$value = $xattr->get($file, $name); // Returns a string, or null if not available
$xattr->set($file, $name, 'new-value'); // This will return nothing.
$file2 = 'path/to/another/file';
$xattr->copy($file, $name, $file2); // Copies the attribute named $name from $file to $file2
$xattr->clone($file, $file2); // Copies all attributes from $file to $file2. Existing attributes in $file2 will remain intact
// Use File object when doing multiple operations on a single file
// All methods from $xattr are available. void methods from Xattr return the object, so they can be chained.
$fileObj = $xattr->file($file); // or new File($file);
$file2Obj = $xattr->file($file2);
$fileObj->set($name, 'another-value')->copy($name, $file2Obj);
$fileObj->clone($file2); // Can use either path, or another File object
$file2Obj->list(); // Will have all the attributes added by $fileObj