File tree Expand file tree Collapse file tree 3 files changed +41
-0
lines changed Expand file tree Collapse file tree 3 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 1
1
Changelog
2
2
=========
3
3
4
+ * 2.2.0 (2015-08-14)
5
+
6
+ * added ` Path::normalize() `
7
+
4
8
* 2.1.0 (2015-07-14)
5
9
6
10
* ` Path::canonicalize() ` now turns ` ~ ` into the user's home directory on
Original file line number Diff line number Diff line change @@ -139,6 +139,30 @@ public static function canonicalize($path)
139
139
return $ canonicalPath ;
140
140
}
141
141
142
+ /**
143
+ * Normalizes the given path.
144
+ *
145
+ * During normalization, all slashes are replaced by forward slashes ("/").
146
+ * Contrary to {@link canonicalize()}, this method does not remove invalid
147
+ * or dot path segments. Consequently, it is much more efficient and should
148
+ * be used whenever the given path is known to be a valid, absolute system
149
+ * path.
150
+ *
151
+ * This method is able to deal with both UNIX and Windows paths.
152
+ *
153
+ * @param string $path A path string.
154
+ *
155
+ * @return string The normalized path.
156
+ *
157
+ * @since 2.2 Added method.
158
+ */
159
+ public static function normalize ($ path )
160
+ {
161
+ Assert::string ($ path , 'The path must be a string. Got: %s ' );
162
+
163
+ return str_replace ('\\' , '/ ' , $ path );
164
+ }
165
+
142
166
/**
143
167
* Returns the directory part of the path.
144
168
*
Original file line number Diff line number Diff line change @@ -1287,4 +1287,17 @@ public function testGetHomeDirectoryForWindows()
1287
1287
1288
1288
$ this ->assertEquals ('C:/users/webmozart ' , Path::getHomeDirectory ());
1289
1289
}
1290
+
1291
+ public function testNormalize ()
1292
+ {
1293
+ $ this ->assertSame ('C:/Foo/Bar/test ' , Path::normalize ('C: \\Foo \\Bar/test ' ));
1294
+ }
1295
+
1296
+ /**
1297
+ * @expectedException \InvalidArgumentException
1298
+ */
1299
+ public function testNormalizeFailsIfNoString ()
1300
+ {
1301
+ Path::normalize (true );
1302
+ }
1290
1303
}
You can’t perform that action at this time.
0 commit comments