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