jbzoo/path
Composer 安装命令:
composer require jbzoo/path
包简介
PHP virtual path library
README 文档
README
A PHP library for creating memory-based aliases for your project file system. This virtual path system allows you to map logical names to physical directories, making file access and URL generation much easier and more maintainable.
Features
- 🚀 Virtual Path Mapping: Create logical aliases for filesystem paths
- 🔗 URL Generation: Automatically generate URLs from file paths
- 📁 Multiple Path Support: Add multiple directories under the same alias
- 🔍 File Resolution: Find files across multiple registered paths
- 🧹 Path Normalization: Clean and normalize file paths
- ⚡ Performance Optimized: Faster than native PHP realpath() in many scenarios
Requirements
- PHP 8.2 or higher
- Composer for installation
Installation
composer require jbzoo/path
Quick Start
Basic Usage
<?php use JBZoo\Path\Path; // Create path instance $path = new Path(); // Set root directory $path->setRoot(__DIR__); // Add path aliases $path ->add(__DIR__ . '/assets/css', 'css') ->add(__DIR__ . '/assets/js', 'js') ->add([ __DIR__ . '/themes/default/css', __DIR__ . '/themes/custom/css' ], 'theme-css'); // Find files using aliases echo $path->get('css:main.css'); // Returns: /project/assets/css/main.css echo $path->get('js:app.js'); // Returns: /project/assets/js/app.js // Generate URLs (if root is web accessible) echo $path->url('css:main.css'); // Returns: https://example.com/assets/css/main.css // Clean and normalize paths echo Path::clean('path\\to//file.txt'); // Returns: 'path/to/file.txt'
Advanced Examples
// Add virtual paths (extending existing aliases) $path->add('css:vendor/bootstrap'); $path->add('css:vendor/fontawesome'); // Get all registered paths for an alias $cssPaths = $path->getPaths('css:'); // Returns array of all CSS directories // Check if file exists in any registered path if ($path->get('css:custom.css')) { echo '<link rel="stylesheet" href="' . $path->url('css:custom.css') . '">'; } // Multiple file types under one alias $path->add([ __DIR__ . '/public/images', __DIR__ . '/uploads/images', __DIR__ . '/cache/optimized' ], 'images'); // Will search in all image directories $logoPath = $path->get('images:logo.png');
Performance
JBZoo Path provides excellent performance compared to native PHP functions. See detailed benchmarks here.
| Subject | Groups | Iterations | Revisions | Mean | StdDev | RStdDev | Memory | Performance |
|---|---|---|---|---|---|---|---|---|
| benchBaseline | 3 | 10000 | 2.53μs | 0.11μs | 4.39% | 6,291,456b | 1.00x | |
| benchNative | 3 | 10000 | 138.22μs | 0.46μs | 0.33% | 6,291,456b | 54.64x | |
| benchJBZooPath | 3 | 10000 | 192.58μs | 0.87μs | 0.45% | 6,291,456b | 76.13x |
Development
Running Tests
# Install/update dependencies make update # Run all tests and code style checks make test-all # Run only PHPUnit tests make test # Run only code style checks make codestyle
Project Structure
src/
├── Path.php # Main Path class
└── Exception.php # Custom exception class
tests/
├── PathTest.php # Main test suite
├── PathPhpStormProxyTest.php # IDE integration tests
├── PathPackageTest.php # Package validation tests
└── phpbench/ # Performance benchmarks
License
MIT
jbzoo/path 适用场景与选型建议
jbzoo/path 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 95.09k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2015 年 12 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「path」 「filesystem」 「url」 「realpath」 「jbzoo」 「virtual path」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jbzoo/path 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jbzoo/path 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jbzoo/path 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A SDK for working with B2 cloud storage.
A PHP class providing static methods for reading, writing, copying, moving, and deleting files and directories, MIME type detection, image size detection, and file permission management
JSONPath implementation for querying and updating JSON objects with support for json flattening into a table
The flysystem adapter for yandex disk rest api.
A sleek PHP wrapper around rclone with Laravel-style fluent API syntax
Easy URL rewrites in your Laravel application
统计信息
- 总下载量: 95.09k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 12
- 依赖项目数: 7
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-12-22