1: <?php
2:
3: namespace WebLoader;
4:
5: class Path
6: {
7:
8: public static function normalize($path)
9: {
10: $path = strtr($path, '\\', '/');
11: $root = (strpos($path, '/') === 0) ? '/' : '';
12: $pieces = explode('/', trim($path, '/'));
13: $res = array();
14:
15: foreach ($pieces as $piece) {
16: if ($piece === '.' || empty($piece)) {
17: continue;
18: }
19: if ($piece === '..') {
20: array_pop($res);
21: } else {
22: array_push($res, $piece);
23: }
24: }
25:
26: return $root . implode('/', $res);
27: }
28:
29: }
30: