Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/riimu/kit-pathjoin
Cross-platform library for normalizing and joining file system paths
https://github.com/riimu/kit-pathjoin
file-path filesystem php php-library
Last synced: about 2 months ago
JSON representation
Cross-platform library for normalizing and joining file system paths
- Host: GitHub
- URL: https://github.com/riimu/kit-pathjoin
- Owner: Riimu
- License: mit
- Created: 2014-12-08T14:01:50.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2017-07-15T13:35:34.000Z (over 7 years ago)
- Last Synced: 2024-11-18T09:56:27.699Z (2 months ago)
- Topics: file-path, filesystem, php, php-library
- Language: PHP
- Homepage: http://kit.riimu.net
- Size: 35.2 KB
- Stars: 11
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE
Awesome Lists containing this project
README
# Path joiner and normalizer #
*PathJoin* is PHP library for normalizing and joining file system paths. The
purpose of this library is to make easier to work with file system paths
irregardless of the platform and the system directory separator.The purpose of file path normalization is to provide a single consistent file
path representation. In other words, the normalization in this library will
resolve `.` and `..` directory references and also condense multiple directory
separators into one. This makes it much easier to avoid common problems when
comparing paths against each other.While PHP provides a built in function `realpath()`, it is not usable in every
case since it works by using the file system. This library simply combines and
normalizes the paths using string handling. There is no requirement for the
files or directories to be readable or even exist.The API documentation is available at: http://kit.riimu.net/api/pathjoin/
[![Travis](https://img.shields.io/travis/Riimu/Kit-PathJoin.svg?style=flat-square)](https://travis-ci.org/Riimu/Kit-PathJoin)
[![Scrutinizer](https://img.shields.io/scrutinizer/g/Riimu/Kit-PathJoin.svg?style=flat-square)](https://scrutinizer-ci.com/g/Riimu/Kit-PathJoin/)
[![Scrutinizer Coverage](https://img.shields.io/scrutinizer/coverage/g/Riimu/Kit-PathJoin.svg?style=flat-square)](https://scrutinizer-ci.com/g/Riimu/Kit-PathJoin/)
[![Packagist](https://img.shields.io/packagist/v/riimu/kit-pathjoin.svg?style=flat-square)](https://packagist.org/packages/riimu/kit-pathjoin)## Requirements ##
* The minimum supported PHP version is 5.6
## Installation ##
### Installation with Composer ###
The easiest way to install this library is to use Composer to handle your
dependencies. In order to install this library via Composer, simply follow
these two steps:1. Acquire the `composer.phar` by running the Composer
[Command-line installation](https://getcomposer.org/download/)
in your project root.2. Once you have run the installation script, you should have the `composer.phar`
file in you project root and you can run the following command:```
php composer.phar require "riimu/kit-pathjoin:^1.2"
```After installing this library via Composer, you can load the library by
including the `vendor/autoload.php` file that was generated by Composer during
the installation.### Adding the library as a dependency ###
If you are already familiar with how to use Composer, you may alternatively add
the library as a dependency by adding the following `composer.json` file to your
project and running the `composer install` command:```json
{
"require": {
"riimu/kit-pathjoin": "^1.2"
}
}
```### Manual installation ###
If you do not wish to use Composer to load the library, you may also download
the library manually by downloading the [latest release](https://github.com/Riimu/Kit-PathJoin/releases/latest)
and extracting the `src` folder to your project. You may then include the
provided `src/autoload.php` file to load the library classes.## Usage ##
This library provides two convenient methods, `Path::normalize()` and
`Path::join()`. Both of these methods work in a very similar fashion. The main
difference is that while the `join()` method can accept multiple paths to join,
the `normalize()` will only accept a single path. Both of the methods will
return a normalized path as the result.The following example will contain numerous different use cases of the library:
```php