nelwhix/filepath
Composer 安装命令:
composer require nelwhix/filepath
包简介
file i/o utilities for different OS architectures
README 文档
README
A simple class with some static methods for manipulating file paths properly regardless of system architecture
Motivation
I was working on a legacy PHP project where there was all sort of code like this:
$routes = include(__DIR_ . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'routes.php');
I then remembered that golang's filepath package would fluently join a url like this. So this is a port of the methods in golang's path/filepath package
Installation
composer require nelwhix/filepath
Usage
- Join Method: Using the static 'join' method the code for the example earlier will look like this:
$url = \Nelwhix\Filepath\Filepath::join(__DIR__, 'src', 'routes.php'); $routes = include($url);
- Base method: The base method returns the last part of any filepath passed to it. Like this:
\Nelwhix\Filepath\Filepath::base("/foo/bar/baz.js"); // this will return "baz.js"
- Abs method: The abs method returns the absolute path to the filepath given:
\Nelwhix\Filepath\Filepath::abs("Filepath.php"); // this returns "\C:\Users\USER PC\Documents\Open Source contributions\filepath\src\Filepath.php"
- Dir method: The dir method returns the directory in a path:
\Nelwhix\Filepath\Filepath::dir("/foo/bar/baz.js") // returns "/foo/bar"
- clean method: The clean method removes double and trailing slashes from a filepath e.g.
\Nelwhix\Filepath\Filepath::clean("//dirty///path////"); // this returns /dirty/path
- ext method: The ext method returns the extension of the file in the filepath. if a directory is passed it returns an empty string.
\Nelwhix\Filepath\Filepath::ext("/src/routes.php"); // returns ".php"
- split method: The split method returns an object that contains the directory and file from the filepath
$split = \Nelwhix\Filepath\Filepath::split("./Documents/side-projects/filepath/composer.json"); $split->dir; // ./Documents/side-projects/filepath $split->file; // composer.json
- walk method: The walk method takes a directory and a callback function to run on each file in the directory.
Filepath::walk("C:\Users\USER PC\Documents\\300L books", function (\DirectoryIterator $param) { if($param->isDot()) return; echo $param->getFilename() . "\n"; });
- glob method: The glob method returns all the files in a directory that match a pattern. To return all the files ending in ".php":
Nelwhix\Filepath\Filepath::glob(".php", "side-projects/src"); // returns an array containing the files matching the pattern
nelwhix/filepath 适用场景与选型建议
nelwhix/filepath 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 05 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 nelwhix/filepath 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nelwhix/filepath 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2023-05-26