germania-kg/pathprefixer

递归地给路径字符串、数组或StdClass对象添加前缀。

1.0.12 2022-03-30 10:07 UTC

This package is auto-updated.

Last update: 2024-08-29 03:47:28 UTC


README

递归地给路径字符串、数组或StdClass对象添加路径前缀。

Packagist PHP version Build Status Scrutinizer Code Quality Code Coverage Build Status

使用Composer安装

$ composer require germania-kg/pathprefixer

用法

<?php
use Germania\PathPrefixer\PathPrefixer;

// Root will default to getcwd()
$prefixer = new PathPrefixer( '/path/to/root' );

echo $prefixer('templates');
// Result: "/path/to/root/templates"


// Try on array:
$result = $prefixer([
	'foo' => 'includes',
	'bar' => 'templates'
]);
// Result: 
//	'foo' => '/path/to/root/includes',
//	'bar' => '/path/to/root/templates'

自定义路径分隔符

默认情况下,将使用 DIRECTORY_SEPARATOR 常量来连接前缀和路径。您也可以传递一个自定义分隔符

<?php
$prefixer = new PathPrefixer( '/path/to/root', "@" );

echo $prefixer('templates');
// Result: "/path/to/root@templates"

问题

查看问题列表。

开发

$ git clone https://github.com/GermaniaKG/PathPrefixer.git
$ cd PathPrefixer
$ composer install

单元测试

可以将 phpunit.xml.dist 复制到 phpunit.xml 并根据需要修改,或者保持原样。运行 PhpUnit 测试或composer脚本,例如这样:

$ composer test
# or
$ vendor/bin/phpunit