Skip to content

Commit 3a70f82

Browse files
committed
deprecate relative paths in makePathRelative()
1 parent ade060e commit 3a70f82

File tree

5 files changed

+18
-3
lines changed

5 files changed

+18
-3
lines changed

UPGRADE-3.4.md

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ Filesystem
6666
* The `Symfony\Component\Filesystem\LockHandler` class has been deprecated,
6767
use the `Symfony\Component\Lock\Store\FlockStore` class
6868
or the `Symfony\Component\Lock\Store\FlockStore\SemaphoreStore` class directly instead.
69+
* support for passing relative paths to `Filesystem::makePathRelative()` is deprecated and will be removed in 4.0
6970

7071
Finder
7172
------

UPGRADE-4.0.md

+1
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ Filesystem
200200
* The `Symfony\Component\Filesystem\LockHandler` has been removed,
201201
use the `Symfony\Component\Lock\Store\FlockStore` class
202202
or the `Symfony\Component\Lock\Store\FlockStore\SemaphoreStore` class directly instead.
203+
* support for passing relative paths to `Filesystem::makePathRelative()` has been removed in 4.0
203204

204205
Finder
205206
------

src/Symfony/Component/Filesystem/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
-----
66

77
* added `appendToFile()` to append contents to existing files
8+
* support for passing relative paths to `Filesystem::makePathRelative()` is deprecated and will be removed in 4.0
89

910
3.2.0
1011
-----

src/Symfony/Component/Filesystem/Filesystem.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,10 @@ public function readlink($path, $canonicalize = false)
446446
*/
447447
public function makePathRelative($endPath, $startPath)
448448
{
449+
if (!$this->isAbsolutePath($endPath) || !$this->isAbsolutePath($startPath)) {
450+
@trigger_error(sprintf('Support for passing relative paths to %s() is deprecated since version 3.4 and will be removed in 4.0.', __METHOD__), E_USER_DEPRECATED);
451+
}
452+
449453
// Normalize separators on Windows
450454
if ('\\' === DIRECTORY_SEPARATOR) {
451455
$endPath = str_replace('\\', '/', $endPath);
@@ -488,7 +492,7 @@ public function makePathRelative($endPath, $startPath)
488492
}
489493

490494
// Determine how deep the start path is relative to the common path (ie, "web/bundles" = 2 levels)
491-
if (count($startPathArr) === 1 && $startPathArr[0] === '') {
495+
if (1 === count($startPathArr) && '' === $startPathArr[0]) {
492496
$depth = 0;
493497
} else {
494498
$depth = count($startPathArr) - $index;
@@ -594,7 +598,7 @@ public function isAbsolutePath($file)
594598
{
595599
return strspn($file, '/\\', 0, 1)
596600
|| (strlen($file) > 3 && ctype_alpha($file[0])
597-
&& substr($file, 1, 1) === ':'
601+
&& ':' === $file[1]
598602
&& strspn($file, '/\\', 2, 1)
599603
)
600604
|| null !== parse_url($file, PHP_URL_SCHEME)

src/Symfony/Component/Filesystem/Tests/FilesystemTest.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,6 @@ public function providePathsForMakePathRelative()
11031103
array('/var/lib/symfony/src/Symfony/', '/var/lib/symfony/src/Symfony/Component/', '../'),
11041104
array('/var/lib/symfony/src/Symfony', '/var/lib/symfony/src/Symfony/Component', '../'),
11051105
array('/var/lib/symfony/src/Symfony', '/var/lib/symfony/src/Symfony/Component/', '../'),
1106-
array('var/lib/symfony/', 'var/lib/symfony/src/Symfony/Component', '../../../'),
11071106
array('/usr/lib/symfony/', '/var/lib/symfony/src/Symfony/Component', '../../../../../../usr/lib/symfony/'),
11081107
array('/var/lib/symfony/src/Symfony/', '/var/lib/symfony/', 'src/Symfony/'),
11091108
array('/aa/bb', '/aa/bb', './'),
@@ -1145,6 +1144,15 @@ public function providePathsForMakePathRelative()
11451144
return $paths;
11461145
}
11471146

1147+
/**
1148+
* @group legacy
1149+
* @expectedDeprecation Support for passing relative paths to Symfony\Component\Filesystem\Filesystem::makePathRelative() is deprecated since version 3.4 and will be removed in 4.0.
1150+
*/
1151+
public function testMakePathRelativeWithRelativePaths()
1152+
{
1153+
$this->assertSame('../../../', $this->filesystem->makePathRelative('var/lib/symfony/', 'var/lib/symfony/src/Symfony/Component'));
1154+
}
1155+
11481156
public function testMirrorCopiesFilesAndDirectoriesRecursively()
11491157
{
11501158
$sourcePath = $this->workspace.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR;

0 commit comments

Comments
 (0)