承接 olinox14/path-php 相关项目开发

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

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

olinox14/path-php

最新稳定版本:0.1.8

Composer 安装命令:

composer require olinox14/path-php

包简介

Object-oriented file and path operations, inspired by the path.py python library

README 文档

README

CI Coverage Status Version License PHP Version Require

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

see https://github.com/PHP-CS-Fixer/PHP-CS-Fixer

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.

统计信息

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

GitHub 信息

  • Stars: 53
  • Watchers: 1
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-03-18