定制 deepeloper/lib-fs 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

deepeloper/lib-fs

最新稳定版本:3.0.0

Composer 安装命令:

composer require deepeloper/lib-fs

包简介

File system library

README 文档

README

Packagist version PHP from Packagist GitHub license GitHub issues Packagist

Donation

Installation

Run composer require deepeloper/lib-fs.

Usage

Tools: walking directory recursively

\deepeloper\Lib\FileSystem\Tools::walkDir(
    "/path/to/dir",
    function (\SplFileInfo $file, $key, array $args) {
        // $args["path"] contains passed "/path/to/dir" ($path)
        echo sprintf(
            "[%s] %s%s", $file->isDir() ? "DIR " : "file",
            $file->getRealPath(),
            PHP_EOL
        );
    }
);

Tools: removing directory recursively

\deepeloper\Lib\FileSystem\Tools::removeDir("/path/to/dir");
// clearstatcache(...);

Tools: searching & replacing recursively

\deepeloper\Lib\FileSystem\Tools::search(
    "/path/to/dir",
    0,           // Flags (php://glob())
    ["*", ".*"], // File name patterns (php://glob())
    ["*", ".*"], // Subdir name patterns (php://glob())
    "needle",    // String to search in files, if starts with "/" processes like regular expression
    function ($path, array $args)
    {
        // $args['path'] contains passed "/path/to/dir" ($dir)
        // $args['needle'] contains passed "needle" ($needle)
        $contents = file_get_contents($path);
        $contents = preg_replace("/needle/", "replacement", $contents);
        file_put_contents($path, $contents);
    }
);

Logging functionality supporting files rotation

$logger = new \deepeloper\Lib\FileSystem\Logger([
    'path'    => "/path/to/log",
    // 'maxSize' => int maxSize,   // Logger::DEFAULT_MAX_SIZE by default.
    // 'rotation' => int rotation, // Rotating files number, 0 means no rotation.
    // 'rights'    => int rights,  // If set after writing to log file chmod() will be called.
]);
$logger->log("Foo");

统计信息

  • 总下载量: 24
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-06-22