将 PHP 中的文件和目录路径进行规范化

v1.1.0 2022-01-22 21:43 UTC

This package is auto-updated.

Last update: 2024-09-23 03:27:11 UTC


README

Build Status

Path2

如果你不确定你的程序能否正确地引导到所需的文件或目录 - 使用 Path2,它将自动将所有斜杠转换为当前操作系统使用的斜杠,同时也将在路径中修剪多余的斜杠。

⚙️ 安装

要安装此库,请在您的终端中运行以下命令

composer require maximgrynykha/path2

用法

<?php

use Path2\Path;

require_once 'vendor/autoload.php';

$path = new Path();

// For example, normalize some kinky path
$normalized = $path->to('/\/src/\\\Path2/\/\/\Path.php');

dd($normalized); // "{CWD}/src/Path2/Path.php" (on an UNIX) || "{CWD}\src\Path2\Path.php" (on a Windows)
                 
                 // Note, by default if any preceding to the main path (first argument),
                 // from-path (second argument) isn't passed then Path::to()
                 // uses CWD (current working directory) as a preceding, from-path.

API

🤝 贡献

如果你使用此库遇到无法解决的问题,请写下你的解决方案。如果你想帮助其他使用此库的开发者(或者如果你想在发布新版本后保持你的解决方案有效,这将在包管理器依赖项中) - 创建一个 pull-request。我将很高兴将你优秀的代码添加到库中!

🐞 在 GitHub 问题 上报告你发现的任何错误或问题。

📃 许可证

MIT 许可证(MIT)。有关更多信息,请参阅 许可证文件