Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/webmozart/path-util
A robust cross-platform utility for normalizing, comparing and modifying file paths.
https://github.com/webmozart/path-util
Last synced: about 4 hours ago
JSON representation
A robust cross-platform utility for normalizing, comparing and modifying file paths.
- Host: GitHub
- URL: https://github.com/webmozart/path-util
- Owner: webmozart
- License: mit
- Created: 2014-11-26T16:44:33.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2021-11-08T08:17:20.000Z (about 3 years ago)
- Last Synced: 2024-10-29T19:18:14.655Z (15 days ago)
- Language: PHP
- Size: 310 KB
- Stars: 473
- Watchers: 9
- Forks: 25
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
File Path Utility
=================[![Build Status](https://travis-ci.org/webmozart/path-util.svg?branch=master)](https://travis-ci.org/webmozart/path-util)
[![Build status](https://ci.appveyor.com/api/projects/status/d5uuypr6p162gpxf/branch/master?svg=true)](https://ci.appveyor.com/project/webmozart/path-util/branch/master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/webmozart/path-util/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/webmozart/path-util/?branch=master)
[![Latest Stable Version](https://poser.pugx.org/webmozart/path-util/v/stable.svg)](https://packagist.org/packages/webmozart/path-util)
[![Total Downloads](https://poser.pugx.org/webmozart/path-util/downloads.svg)](https://packagist.org/packages/webmozart/path-util)
[![Dependency Status](https://www.versioneye.com/php/webmozart:path-util/2.3.0/badge.svg)](https://www.versioneye.com/php/webmozart:path-util/2.3.0)Latest release: [2.3.0](https://packagist.org/packages/webmozart/path-util#2.3.0)
PHP >= 5.3.3
This package provides robust, cross-platform utility functions for normalizing,
comparing and modifying file paths and URLs.Deprecation
-----------This package has been merged into [the Symfony Filesystem Component 5.4]. It is not maintained anymore.
Installation
------------The utility can be installed with [Composer]:
```
$ composer require webmozart/path-util
```Usage
-----Use the `Path` class to handle file paths:
```php
use Webmozart\PathUtil\Path;echo Path::canonicalize('/var/www/vhost/webmozart/../config.ini');
// => /var/www/vhost/config.iniecho Path::canonicalize('C:\Programs\Webmozart\..\config.ini');
// => C:/Programs/config.iniecho Path::canonicalize('~/config.ini');
// => /home/webmozart/config.iniecho Path::makeAbsolute('config/config.yml', '/var/www/project');
// => /var/www/project/config/config.ymlecho Path::makeRelative('/var/www/project/config/config.yml', '/var/www/project/uploads');
// => ../config/config.yml$paths = array(
'/var/www/vhosts/project/httpdocs/config/config.yml',
'/var/www/vhosts/project/httpdocs/images/banana.gif',
'/var/www/vhosts/project/httpdocs/uploads/../images/nicer-banana.gif',
);Path::getLongestCommonBasePath($paths);
// => /var/www/vhosts/project/httpdocsPath::getFilename('/views/index.html.twig');
// => index.html.twigPath::getFilenameWithoutExtension('/views/index.html.twig');
// => index.htmlPath::getFilenameWithoutExtension('/views/index.html.twig', 'html.twig');
Path::getFilenameWithoutExtension('/views/index.html.twig', '.html.twig');
// => indexPath::getExtension('/views/index.html.twig');
// => twigPath::hasExtension('/views/index.html.twig');
// => truePath::hasExtension('/views/index.html.twig', 'twig');
// => truePath::hasExtension('/images/profile.jpg', array('jpg', 'png', 'gif'));
// => truePath::changeExtension('/images/profile.jpeg', 'jpg');
// => /images/profile.jpgPath::join('phar://C:/Documents', 'projects/my-project.phar', 'composer.json');
// => phar://C:/Documents/projects/my-project.phar/composer.jsonPath::getHomeDirectory();
// => /home/webmozart
```Use the `Url` class to handle URLs:
```php
use Webmozart\PathUtil\Url;echo Url::makeRelative('http://example.com/css/style.css', 'http://example.com/puli');
// => ../css/style.cssecho Url::makeRelative('http://cdn.example.com/css/style.css', 'http://example.com/puli');
// => http://cdn.example.com/css/style.css
```Learn more in the [Documentation] and the [API Docs].
Authors
-------* [Bernhard Schussek] a.k.a. [@webmozart]
* [The Community Contributors]Documentation
-------------Read the [Documentation] if you want to learn more about the contained functions.
Contribute
----------Contributions are always welcome!
* Report any bugs or issues you find on the [issue tracker].
* You can grab the source code at the [Git repository].Support
-------If you are having problems, send a mail to [email protected] or shout out to
[@webmozart] on Twitter.License
-------All contents of this package are licensed under the [MIT license].
[Bernhard Schussek]: http://webmozarts.com
[The Community Contributors]: https://github.com/webmozart/path-util/graphs/contributors
[Composer]: https://getcomposer.org
[Documentation]: docs/usage.md
[API Docs]: https://webmozart.github.io/path-util/api/latest/class-Webmozart.PathUtil.Path.html
[issue tracker]: https://github.com/webmozart/path-util/issues
[Git repository]: https://github.com/webmozart/path-util
[@webmozart]: https://twitter.com/webmozart
[MIT license]: LICENSE
[the Symfony Filesystem Component 5.4]: https://github.com/symfony/filesystem/tree/5.4