8000 feature #24202 [Filesystem] deprecate relative paths in makePathRelat… · symfony/symfony@7269013 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7269013

Browse files
committed
feature #24202 [Filesystem] deprecate relative paths in makePathRelative() (xabbuh)
This PR was merged into the 3.4 branch. Discussion ---------- [Filesystem] deprecate relative paths in makePathRelative() | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Commits ------- 893df58 deprecate relative paths in makePathRelative()
2 parents f7eb797 + 893df58 commit 7269013

File tree

5 files changed

+17
-2
lines changed

5 files changed

+17
-2
lines changed

UPGRADE-3.4.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ Filesystem
6969
* The `Symfony\Component\Filesystem\LockHandler` class has been deprecated,
7070
use the `Symfony\Component\Lock\Store\FlockStore` class
7171
or the `Symfony\Component\Lock\Store\FlockStore\SemaphoreStore` class directly instead.
72+
* Support for passing relative paths to `Filesystem::makePathRelative()` is deprecated and will be removed in 4.0.
7273

7374
Finder
7475
------

UPGRADE-4.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ Filesystem
205205
* The `Symfony\Component\Filesystem\LockHandler` has been removed,
206206
use the `Symfony\Component\Lock\Store\FlockStore` class
207207
or the `Symfony\Component\Lock\Store\FlockStore\SemaphoreStore` class directly instead.
208+
* Support for passing relative paths to `Filesystem::makePathRelative()` has been removed.
208209

209210
Finder
210211
------

src/Symfony/Component/Filesystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
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

Lines changed: 5 additions & 1 deletion
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);
@@ -596,7 +600,7 @@ public function isAbsolutePath($file)
596600
{
597601
return strspn($file, '/\\', 0, 1)
598602
|| (strlen($file) > 3 && ctype_alpha($file[0])
599-
&& ':' === substr($file, 1, 1)
603+
&& ':' === $file[1]
600604
&& strspn($file, '/\\', 2, 1)
601605
)
602606
|| null !== parse_url($file, PHP_URL_SCHEME)

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

Lines changed: 9 additions & 1 deletion
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)
0