ichhabrecht/filesystem

高级文件系统功能库

0.4.1 2016-09-12 19:36 UTC

This package is auto-updated.

Last update: 2024-09-11 14:57:20 UTC


README

高级文件系统功能库。

Latest Stable Version Build Status

安装

建议使用 Composer 将 filesystem 包含到您的项目中。

$ composer require ichhabrecht/filesystem

使用方法

Fileidentity

$fileidentity = new \IchHabRecht\Filesystem\Fileidentity();
if (!$fileidentity->canBeValidated('/path/to/file') || $fileidentity->isValid('/path/to/file')) {
    // Do something
}

canBeValidated

检查文件扩展名是否在 Fileidentity 类中注册了签名,从而可以验证其内容。

isValid

测试文件的第一个字节是否根据其已知的签名有效。如果文件不存在或不可读,则抛出错误。您可以使用 canBeValidated() 确保文件可以被验证。

Filemode

$filemode = new \IchHabRecht\Filesystem\Filemode();
$filemode->setPermissions('/path/to/adjust', $settings);

设置

设置参数是一个数组,其中包含名为 filefolder 的键,或者两者都有。

您可以使用字符串值强制设置权限,或者通过在数组中定义它们来确保不同的权限。

// This sets file permissions to read and execute (5) and folder permissions to read, write and execute (7)
$settings = [
    'file' => '555',
    'folder' => '777',
];

// This ensures read and write access (6) for files, as well as write and execute access (3) for folders
$settings = [
    'file' => [
        'user' => 6,
        'group' => 6,
        'other' => 6,
    ],
    'folder' => [
        'user' => 3,
        'group' => 3,
        'other' => 3,
    ],
];

您可以为 usergroupother 值使用不同的权限,或者仅指定您要确保的权限。

Filepath

$filepath = new \IchHabRecht\Filesystem\Filepath('/', true);
$filepath->concatenate('/var/', 'www', 'vhosts'); // Returns '/var/www/vhosts'
$filepath->ensureDirectorySeparator('C:\\Users\\All Users\\Favorites'); // Returns 'C:/Users/All Users/Favorites'
$filepath->normalize('/var/www/./../../vhosts'); // Returns '/vhosts'

初始化

如果您初始化一个新对象,您可以指定用于进一步处理的 目录分隔符,以及声明是否应该对此路径 强制执行 此分隔符。目录分隔符可以是斜杠或反斜杠。

连接

您可以向此函数传递任意数量的 string 参数。所有参数都使用指定的目录分隔符连接。删除尾随斜杠。

EnsureDirectorySeparator

将所有目录分隔符 (/\) 转换为指定的分隔符。

标准化

这些函数删除重复的(或多个)目录分隔符并解析路径遍历。