olinox14/path-php
Composer 安装命令:
composer require olinox14/path-php
包简介
Object-oriented file and path operations, inspired by the path.py python library
README 文档
README
Path-php
An intuitive, standalone, and object-oriented library for file and path operations.
See the full documentation here : Documentation
<?php use Path\Path; // Get the parent directory of the current script file and list its subdirs $script = new Path(__file__); $dir = $script->parent(); var_dump($dir->dirs()); // Get the path of the working directory, iterate over its files and change their permissions $path = new Path('.'); foreach($path->files() as $file) { $file->chmod(755); } // Put content into a file $path = (new Path('.'))->append('readme.md'); $path->putContent('new readme content'); // And many more...
Requirement
path-php requires php8.0 or ulterior versions.
Installation
Install with composer :
composer require olinox14/path-php
Usage
Import the Path class :
use Path\Path;
Instantiate with some path :
$path = new Path('./foo'); $path = new Path('/foo/bar/file.ext'); $path = new Path(__file__);
And use it as needed. For example, if you want to rename all the html files in the directory where your current script lies into .md files :
$path = new Path(__file__); $dir = $path->parent(); foreach ($dir->files() as $file) { if ($file->ext() === 'html') { $file->rename($file->name() . '.md'); } }
Contribute
Git branching
Contributions shall follow the gitflow pattern.
Tests
First build
Default php version in the dockerfile is set to be the oldest actively supported version of php, but you can change it locally before building your container.
Build your docker container :
docker build -t path .
Run it (name can be changed):
# On Linux
docker run -v "$(pwd)":/path --name path path
# On Windows
docker run -d -v "%cd%:/path" --name path path
Execute it and install dependencies :
docker exec -it path bash
composer install
Run the unit tests :
XDEBUG_MODE=coverage vendor/bin/phpunit -c phpunit.xml
Run on a built container
If you've already built your container, start it and run unit tests with :
docker start path
docker exec -it path bash
XDEBUG_MODE=coverage vendor/bin/phpunit -c phpunit.xml
Run code quality tools
Phpstan
Build and start the docker as explained in the unit tests section, then run :
vendor/bin/phpstan analyse --memory-limit=-1
see: https://phpstan.org/
CS Fixer
Build and start the docker as explained in the unit tests section, then run :
vendor/bin/php-cs-fixer fix src
Generate documentation
To install and run phpdoc :
docker pull phpdoc/phpdoc
# On Linux
docker run --rm -v "$(pwd):/data" "phpdoc/phpdoc:3"
# On Windows
docker run --rm -v "%cd%:/data" "phpdoc/phpdoc:3"
If you're on Linux, you could create an alias with :
alias phpdoc="docker run --rm -v $(pwd):/data phpdoc/phpdoc:3"
Licence
Path-php is under the MIT licence.
olinox14/path-php 适用场景与选型建议
olinox14/path-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 662 次下载、GitHub Stars 达 54, 最近一次更新时间为 2024 年 03 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 olinox14/path-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 olinox14/path-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 662
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 54
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-03-18