2017 © Pedro Peláez
 

library path-util

A robust cross-platform utility for normalizing, comparing and modifying file paths.

image

webmozart/path-util

A robust cross-platform utility for normalizing, comparing and modifying file paths.

  • Monday, August 15, 2016
  • by webmozart
  • Repository
  • 8 Watchers
  • 250 Stars
  • 3,469,396 Installations
  • PHP
  • 225 Dependents
  • 0 Suggesters
  • 16 Forks
  • 4 Open issues
  • 12 Versions
  • 14 % Grown

The README.md

File Path Utility

Build Status Build status Scrutinizer Code Quality Latest Stable Version Total Downloads Dependency Status, (*1)

Latest release: 2.3.0, (*2)

PHP >= 5.3.3, (*3)

This package provides robust, cross-platform utility functions for normalizing, comparing and modifying file paths and URLs., (*4)

Deprecation

This package has been merged into the Symfony Filesystem Component 5.4. It is not maintained anymore., (*5)

Installation

The utility can be installed with Composer:, (*6)

$ composer require webmozart/path-util

Usage

Use the Path class to handle file paths:, (*7)

use Webmozart\PathUtil\Path;

echo Path::canonicalize('/var/www/vhost/webmozart/../config.ini');
// => /var/www/vhost/config.ini

echo Path::canonicalize('C:\Programs\Webmozart\..\config.ini');
// => C:/Programs/config.ini

echo Path::canonicalize('~/config.ini');
// => /home/webmozart/config.ini

echo Path::makeAbsolute('config/config.yml', '/var/www/project');
// => /var/www/project/config/config.yml

echo 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/httpdocs

Path::getFilename('/views/index.html.twig');
// => index.html.twig

Path::getFilenameWithoutExtension('/views/index.html.twig');
// => index.html

Path::getFilenameWithoutExtension('/views/index.html.twig', 'html.twig');
Path::getFilenameWithoutExtension('/views/index.html.twig', '.html.twig');
// => index

Path::getExtension('/views/index.html.twig');
// => twig

Path::hasExtension('/views/index.html.twig');
// => true

Path::hasExtension('/views/index.html.twig', 'twig');
// => true

Path::hasExtension('/images/profile.jpg', array('jpg', 'png', 'gif'));
// => true

Path::changeExtension('/images/profile.jpeg', 'jpg');
// => /images/profile.jpg

Path::join('phar://C:/Documents', 'projects/my-project.phar', 'composer.json');
// => phar://C:/Documents/projects/my-project.phar/composer.json

Path::getHomeDirectory();
// => /home/webmozart

Use the Url class to handle URLs:, (*8)

use Webmozart\PathUtil\Url;

echo Url::makeRelative('http://example.com/css/style.css', 'http://example.com/puli');
// => ../css/style.css

echo 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., (*9)

Authors

Documentation

Read the Documentation if you want to learn more about the contained functions., (*10)

Contribute

Contributions are always welcome!, (*11)

Support

If you are having problems, send a mail to bschussek@gmail.com or shout out to @webmozart on Twitter., (*12)

License

All contents of this package are licensed under the MIT license., (*13)

The Versions

15/08 2016

dev-master

9999999-dev

A robust cross-platform utility for normalizing, comparing and modifying file paths.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernhard Schussek

17/12 2015

2.3.0

2.3.0.0

A robust cross-platform utility for normalizing, comparing and modifying file paths.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernhard Schussek

05/10 2015

2.2.3

2.2.3.0

A robust cross-platform utility for normalizing, comparing and modifying file paths.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernhard Schussek

24/08 2015

2.2.2

2.2.2.0

A robust cross-platform utility for normalizing, comparing and modifying file paths.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernhard Schussek

24/08 2015

2.2.1

2.2.1.0

A robust cross-platform utility for normalizing, comparing and modifying file paths.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernhard Schussek

14/08 2015

2.2.0

2.2.0.0

A robust cross-platform utility for normalizing, comparing and modifying file paths.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernhard Schussek

14/07 2015

2.1.0

2.1.0.0

A robust cross-platform utility for normalizing, comparing and modifying file paths.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernhard Schussek

21/05 2015

2.0.0

2.0.0.0

A robust cross-platform utility for normalizing, comparing and modifying file paths.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernhard Schussek

19/03 2015

1.1.0

1.1.0.0

A robust cross-platform utility for normalizing, comparing and modifying file paths.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

by Bernhard Schussek

12/01 2015

1.0.2

1.0.2.0

A robust cross-platform utility for normalizing, comparing and modifying file paths.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

by Bernhard Schussek

03/12 2014

1.0.1

1.0.1.0

A robust cross-platform utility for normalizing, comparing and modifying file paths.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

by Bernhard Schussek

26/11 2014

1.0.0

1.0.0.0

A robust cross-platform utility for normalizing, comparing and modifying file paths.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

by Bernhard Schussek