germania-kg / pathprefixer
Recursively prepends a prefix to path string, array or StdClass objects.
1.0.12
2022-03-30 10:07 UTC
Requires
- php: ^5.6|^7.0
- psr/log: ^1.0
Requires (Dev)
- php-coveralls/php-coveralls: ^2.0
- phpunit/phpunit: ^5.7|^6.0
README
Recursively prepends a path prefix to path string, array or StdClass objects.
Installation with Composer
$ composer require germania-kg/pathprefixer
Usage
<?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'
Custom path separators
Per default, the DIRECTORY_SEPARATOR
constant will be used for glueing the prefix and the path.
You may pass a custom seperator as well:
<?php $prefixer = new PathPrefixer( '/path/to/root', "@" ); echo $prefixer('templates'); // Result: "/path/to/root@templates"
Issues
See issues list.
Development
$ git clone https://github.com/GermaniaKG/PathPrefixer.git
$ cd PathPrefixer
$ composer install
Unit tests
Either copy phpunit.xml.dist
to phpunit.xml
and adapt to your needs, or leave as is. Run PhpUnit test or composer scripts like this:
$ composer test # or $ vendor/bin/phpunit