annotate vendor/webmozart/path-util/README.md @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 File Path Utility
Chris@0 2 =================
Chris@0 3
Chris@0 4 [![Build Status](https://travis-ci.org/webmozart/path-util.svg?branch=2.3.0)](https://travis-ci.org/webmozart/path-util)
Chris@0 5 [![Build status](https://ci.appveyor.com/api/projects/status/d5uuypr6p162gpxf/branch/master?svg=true)](https://ci.appveyor.com/project/webmozart/path-util/branch/master)
Chris@0 6 [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/webmozart/path-util/badges/quality-score.png?b=2.3.0)](https://scrutinizer-ci.com/g/webmozart/path-util/?branch=2.3.0)
Chris@0 7 [![Latest Stable Version](https://poser.pugx.org/webmozart/path-util/v/stable.svg)](https://packagist.org/packages/webmozart/path-util)
Chris@0 8 [![Total Downloads](https://poser.pugx.org/webmozart/path-util/downloads.svg)](https://packagist.org/packages/webmozart/path-util)
Chris@0 9 [![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)
Chris@0 10
Chris@0 11 Latest release: [2.3.0](https://packagist.org/packages/webmozart/path-util#2.3.0)
Chris@0 12
Chris@0 13 PHP >= 5.3.3
Chris@0 14
Chris@0 15 This package provides robust, cross-platform utility functions for normalizing,
Chris@0 16 comparing and modifying file paths and URLs.
Chris@0 17
Chris@0 18 Installation
Chris@0 19 ------------
Chris@0 20
Chris@0 21 The utility can be installed with [Composer]:
Chris@0 22
Chris@0 23 ```
Chris@0 24 $ composer require webmozart/path-util
Chris@0 25 ```
Chris@0 26
Chris@0 27 Usage
Chris@0 28 -----
Chris@0 29
Chris@0 30 Use the `Path` class to handle file paths:
Chris@0 31
Chris@0 32 ```php
Chris@0 33 use Webmozart\PathUtil\Path;
Chris@0 34
Chris@0 35 echo Path::canonicalize('/var/www/vhost/webmozart/../config.ini');
Chris@0 36 // => /var/www/vhost/config.ini
Chris@0 37
Chris@0 38 echo Path::canonicalize('C:\Programs\Webmozart\..\config.ini');
Chris@0 39 // => C:/Programs/config.ini
Chris@0 40
Chris@0 41 echo Path::canonicalize('~/config.ini');
Chris@0 42 // => /home/webmozart/config.ini
Chris@0 43
Chris@0 44 echo Path::makeAbsolute('config/config.yml', '/var/www/project');
Chris@0 45 // => /var/www/project/config/config.yml
Chris@0 46
Chris@0 47 echo Path::makeRelative('/var/www/project/config/config.yml', '/var/www/project/uploads');
Chris@0 48 // => ../config/config.yml
Chris@0 49
Chris@0 50 $paths = array(
Chris@0 51 '/var/www/vhosts/project/httpdocs/config/config.yml',
Chris@0 52 '/var/www/vhosts/project/httpdocs/images/banana.gif',
Chris@0 53 '/var/www/vhosts/project/httpdocs/uploads/../images/nicer-banana.gif',
Chris@0 54 );
Chris@0 55
Chris@0 56 Path::getLongestCommonBasePath($paths);
Chris@0 57 // => /var/www/vhosts/project/httpdocs
Chris@0 58
Chris@0 59 Path::getFilename('/views/index.html.twig');
Chris@0 60 // => index.html.twig
Chris@0 61
Chris@0 62 Path::getFilenameWithoutExtension('/views/index.html.twig');
Chris@0 63 // => index.html
Chris@0 64
Chris@0 65 Path::getFilenameWithoutExtension('/views/index.html.twig', 'html.twig');
Chris@0 66 Path::getFilenameWithoutExtension('/views/index.html.twig', '.html.twig');
Chris@0 67 // => index
Chris@0 68
Chris@0 69 Path::getExtension('/views/index.html.twig');
Chris@0 70 // => twig
Chris@0 71
Chris@0 72 Path::hasExtension('/views/index.html.twig');
Chris@0 73 // => true
Chris@0 74
Chris@0 75 Path::hasExtension('/views/index.html.twig', 'twig');
Chris@0 76 // => true
Chris@0 77
Chris@0 78 Path::hasExtension('/images/profile.jpg', array('jpg', 'png', 'gif'));
Chris@0 79 // => true
Chris@0 80
Chris@0 81 Path::changeExtension('/images/profile.jpeg', 'jpg');
Chris@0 82 // => /images/profile.jpg
Chris@0 83
Chris@0 84 Path::join('phar://C:/Documents', 'projects/my-project.phar', 'composer.json');
Chris@0 85 // => phar://C:/Documents/projects/my-project.phar/composer.json
Chris@0 86
Chris@0 87 Path::getHomeDirectory();
Chris@0 88 // => /home/webmozart
Chris@0 89 ```
Chris@0 90
Chris@0 91 Use the `Url` class to handle URLs:
Chris@0 92
Chris@0 93 ```php
Chris@0 94 use Webmozart\PathUtil\Url;
Chris@0 95
Chris@0 96 echo Url::makeRelative('http://example.com/css/style.css', 'http://example.com/puli');
Chris@0 97 // => ../css/style.css
Chris@0 98
Chris@0 99 echo Url::makeRelative('http://cdn.example.com/css/style.css', 'http://example.com/puli');
Chris@0 100 // => http://cdn.example.com/css/style.css
Chris@0 101 ```
Chris@0 102
Chris@0 103 Learn more in the [Documentation] and the [API Docs].
Chris@0 104
Chris@0 105 Authors
Chris@0 106 -------
Chris@0 107
Chris@0 108 * [Bernhard Schussek] a.k.a. [@webmozart]
Chris@0 109 * [The Community Contributors]
Chris@0 110
Chris@0 111 Documentation
Chris@0 112 -------------
Chris@0 113
Chris@0 114 Read the [Documentation] if you want to learn more about the contained functions.
Chris@0 115
Chris@0 116 Contribute
Chris@0 117 ----------
Chris@0 118
Chris@0 119 Contributions are always welcome!
Chris@0 120
Chris@0 121 * Report any bugs or issues you find on the [issue tracker].
Chris@0 122 * You can grab the source code at the [Git repository].
Chris@0 123
Chris@0 124 Support
Chris@0 125 -------
Chris@0 126
Chris@0 127 If you are having problems, send a mail to bschussek@gmail.com or shout out to
Chris@0 128 [@webmozart] on Twitter.
Chris@0 129
Chris@0 130 License
Chris@0 131 -------
Chris@0 132
Chris@0 133 All contents of this package are licensed under the [MIT license].
Chris@0 134
Chris@0 135 [Bernhard Schussek]: http://webmozarts.com
Chris@0 136 [The Community Contributors]: https://github.com/webmozart/path-util/graphs/contributors
Chris@0 137 [Composer]: https://getcomposer.org
Chris@0 138 [Documentation]: docs/usage.md
Chris@0 139 [API Docs]: https://webmozart.github.io/path-util/api/latest/class-Webmozart.PathUtil.Path.html
Chris@0 140 [issue tracker]: https://github.com/webmozart/path-util/issues
Chris@0 141 [Git repository]: https://github.com/webmozart/path-util
Chris@0 142 [@webmozart]: https://twitter.com/webmozart
Chris@0 143 [MIT license]: LICENSE