HSA Test User c16dcac362 User import | 7 jaren geleden | |
---|---|---|
.. | ||
docs | 7 jaren geleden | |
src | 7 jaren geleden | |
tests | 7 jaren geleden | |
.gitignore | 7 jaren geleden | |
.styleci.yml | 7 jaren geleden | |
.travis.yml | 7 jaren geleden | |
CHANGELOG.md | 7 jaren geleden | |
LICENSE | 7 jaren geleden | |
README.md | 7 jaren geleden | |
appveyor.yml | 7 jaren geleden | |
composer.json | 7 jaren geleden | |
phpunit.xml.dist | 7 jaren geleden |
Latest release: 2.3.0
PHP >= 5.3.3
This package provides robust, cross-platform utility functions for normalizing, comparing and modifying file paths and URLs.
The utility can be installed with Composer:
$ composer require webmozart/path-util
Use the Path
class to handle file paths:
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:
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.
Read the Documentation if you want to learn more about the contained functions.
Contributions are always welcome!
If you are having problems, send a mail to bschussek@gmail.com or shout out to @webmozart on Twitter.
All contents of this package are licensed under the MIT license.