承接 tasoft/tools-path 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

tasoft/tools-path

Composer 安装命令:

composer require tasoft/tools-path

包简介

Simple library to manipulate virtual paths

README 文档

README

This PHP library is a small tool to manage virtual paths.
Virtual paths are paths that don't have to exist on file system.

That leads to the problem of recognize if a path is a directory or a file.
To solve this problem, the library declares virtual paths using the following notations:

  • Path with leading / is a zero path or absolute path.
  • Path with tailing / is a directory
  • component .. is parent directory
  • component . is current directory
  • empty components are ignored (ex: /path///to/file.txt => /path/to/file.txt)

So the Path Tool provides two methods to determine if a path is a zero path or a directory

use TASoft\Util\PathTool;
PathTool::isZeroPath("/my/path");       // TRUE
PathTool::isZeroPath("../path/");       // FALSE

PathTool::isDirectory("my/path/to/");   // TRUE
PathTool::isDirectory("/my/path.txt");  // FALSE
PathTool::isDirectory("/my/path.txt/"); // TRUE

The core of PathTool is the method yieldPathComponents. It feeds other methods with path components. You can also use it directly with options described here:

  • OPTION_RESOLVE: Resolves empty directories, parent and current directories.
  • OPTION_DENY_OUT_OF_BOUNDS: Does not allow to choose parent directory of root directory (ex: /root/path/../../../)
  • OPTION_YIELD_ROOT: If a zero path, yields / as first component.
  • OPTION_YIELD_COMPONENT: Yields PathComponent object instead of strings.
  • OPTION_ALL: Include all options described before.
// Use bitwise operators to join options:
$options = PathTool::OPTION_RESOLVE | PathTool::OPTION_YIELD_ROOT;

// Or subtract them
$options = PathTool::OPTION_ALL & ~PathTool::OPTION_DENY_OUT_OF_BOUNDS & ~PathTool::OPTION_YIELD_ROOT;

Usage

use TASoft\Util\PathTool;

// Normalize
echo PathTool::normalize("/my/path/./to////oops/../../file.txt"); // /my/path/file.txt
echo PathTool::normalize("/path/../../");                         // Fails!
// Out of bounds!                  ^^

echo PathTool::normalize("path/../../");                          // ../

// Relative
// Works only with zero paths!
echo PathTool::relative("/my/dir/1/", "/my/dir/1/file.txt");      // file.txt
echo PathTool::relative("/my/dir/1/", "my/dir/1/file.txt");       // Fails!
// not a zero path                     ^

echo PathTool::relative("/my/dir/1", "/my/dir/2");                // 2 (because /my/dir/1 is a file)
echo PathTool::relative("/my/dir/1/", "/my/dir/2");               // ../2

echo PathTool::relative("/my/dir/1", "/my/dir/2/");               // 2/
echo PathTool::relative("/my/dir/1/", "/my/dir/2/");              // ../2/

echo PathTool::relative("/path/file.txt", "/path/file.txt");      // ""
echo PathTool::relative("/path/file.txt", "/path/");              // ./

Real Path Tool

The RealPathTool allows to perform simple task on real files and directories such as iterating over contents.

<?php
use TASoft\Util\RealPathTool as Tool;

tasoft/tools-path 适用场景与选型建议

tasoft/tools-path 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 372 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 04 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 tasoft/tools-path 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 tasoft/tools-path 我们能提供哪些服务?
定制开发 / 二次开发

基于 tasoft/tools-path 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-04-26