An intuitive, standalone, and object-oriented library for file and path operations.
See the full documentation here : Documentation
<?phpusePath\Path;
// Get the parent directory of the current script file and list its subdirs$script = newPath(__file__);
$dir = $script->parent();
var_dump($dir->dirs());
// Get the path of the working directory, iterate over its files and change their permissions$path = newPath('.');
foreach($path->files() as$file) {
$file->chmod(755);
}
// Put content into a file $path = (newPath('.'))->append('readme.md');
$path->putContent('new readme content');
// And many more...path-php requires php8.0 or ulterior versions.
Install with composer :
composer require olinox14/path-php
Import the Path class :
usePath\Path;Instantiate with some path :
$path = newPath('./foo');
$path = newPath('/foo/bar/file.ext');
$path = newPath(__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 = newPath(__file__);
$dir = $path->parent();
foreach ($dir->files() as$file) {
if ($file->ext() === 'html') {
$file->rename($file->name() . '.md');
}
}Contributions shall follow the gitflow pattern.
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
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
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/
Build and start the docker as explained in the unit tests section, then run :
vendor/bin/php-cs-fixer fix src
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"
Path-php is under the MIT licence.