weevers / path
此包已被废弃,不再维护。未建议替代包。
node/iojs path 模块的 PHP 5.4 端口
v0.2.0
2015-04-02 00:12 UTC
Requires
- php: >=5.4.0
Requires (Dev)
- phpunit/phpunit: 4.5.*
This package is not auto-updated.
Last update: 2020-08-08 17:28:15 UTC
README
PHP 5.4 端口的 node/iojs path 模块,因为 PHP 就像是一个家庭假日聚餐,我希望能够生存下来。来自 iojs 文档的描述
此模块包含处理和转换文件路径的实用工具。几乎所有这些方法仅执行字符串转换。不会咨询文件系统以检查路径是否有效。
示例
在 POSIX 系统上的示例输出,假设 "/please" 是当前工作目录
<?php use Weevers\Path\Path; // "../../tolerate/php" Path::relative('i/love/node', 'i/tolerate/php'); // "/alright" (resolve works like a sequence of cd commands in a shell) Path::resolve('ah', '/okay', '../alright'); // true Path::isInside('parent/child', 'parent'); // "/please/start/dancing" Path::resolve('start', 'dancing'); ?>
用法
用法文档待定。在此期间,请参考 iojs 文档,因为函数签名几乎相同,代码(包括单元测试)已复制。
已移植的内容(针对 POSIX 和 Windows,包括单元测试)
relative($from, $to)isAbsolute($path)resolve($path, ..)join($path, ..)normalize($path)separator()delimiter()
PHP 特定添加
resolve() 也可以接受流包装器 URI。这是在 (移植的) POSIX 和 Windows 适配器之外实现的,以确保它不会干扰原始行为(该行为经过良好测试并且具有冻结的稳定性)。
- 除非与其他方案组合,否则会移除
file方案 - 方案更改会被解释为根更改。例如,从
http://x到glob://x的行为类似于从c:\x到d:\x的cd命令。 - 对于远程流(如
http)和 vfs 流,将传递给resolve()的参数用正斜杠连接(无论操作系统如何)。
一些示例(针对 Windows,以便您可以看到本地流和远程流之间的区别),假设 "C:\project" 是当前工作目录
<?php // Relative input: "c:\project\beep" Path::resolve('file://beep'); Path::resolve('beep'); // Absolute input: "c:\beep" Path::resolve('file:///beep'); Path::resolve('/beep'); // Combined wrappers: "zip://file://c:\beep" Path::resolve('zip://file:///beep'); // Remote stream, so forward slashes: "zip://http://example.com/blog/2015" Path::resolve('zip://http://example.com\blog', '2015'); // "zip://c:\project\bar" Path::resolve('zip://dir', '..', 'bar'); Path::resolve('dir', 'zip://..', 'bar'); // A VFS URI stays relative: "vfs://root/virtual.file" Path::resolve('vfs://root', 'virtual.file'); // A scheme change: "glob://c:\project\*.js" Path::resolve('http://example.com', 'glob://*.js'); // No scheme change: "glob://c:\project\dir\*.js" Path::resolve('glob://dir', 'glob://*.js'); // UNC (a network path): "compress.zlib://\\server\share\resource" // Note that "\\server\share" is the root, so ".." has no effect Path::resolve('compress.zlib:////server/share', '..', 'resource'); ?>
附加方法
isInside($path, $parent)- 与 node 的 sindresorhus/is-path-inside 类似getPrefix($path)- 对于 "zip://2015.zip#april/02.log",返回 "zip://"
安装
使用 composer
composer require weevers/path