Skip to content

Commit

Permalink
feature #24202 [Filesystem] deprecate relative paths in makePathRelat…
Browse files Browse the repository at this point in the history
…ive() (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()
  • Loading branch information
fabpot committed Sep 27, 2017
2 parents f7eb797 + 893df58 commit 7269013
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions UPGRADE-3.4.md
Expand Up @@ -69,6 +69,7 @@ Filesystem
* The `Symfony\Component\Filesystem\LockHandler` class has been deprecated,
use the `Symfony\Component\Lock\Store\FlockStore` class
or the `Symfony\Component\Lock\Store\FlockStore\SemaphoreStore` class directly instead.
* Support for passing relative paths to `Filesystem::makePathRelative()` is deprecated and will be removed in 4.0.

Finder
------
Expand Down
1 change: 1 addition & 0 deletions UPGRADE-4.0.md
Expand Up @@ -205,6 +205,7 @@ Filesystem
* The `Symfony\Component\Filesystem\LockHandler` has been removed,
use the `Symfony\Component\Lock\Store\FlockStore` class
or the `Symfony\Component\Lock\Store\FlockStore\SemaphoreStore` class directly instead.
* Support for passing relative paths to `Filesystem::makePathRelative()` has been removed.

Finder
------
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Filesystem/CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@ CHANGELOG
-----

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

3.2.0
-----
Expand Down
6 changes: 5 additions & 1 deletion src/Symfony/Component/Filesystem/Filesystem.php
Expand Up @@ -446,6 +446,10 @@ public function readlink($path, $canonicalize = false)
*/
public function makePathRelative($endPath, $startPath)
{
if (!$this->isAbsolutePath($endPath) || !$this->isAbsolutePath($startPath)) {
@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);
}

// Normalize separators on Windows
if ('\\' === DIRECTORY_SEPARATOR) {
$endPath = str_replace('\\', '/', $endPath);
Expand Down Expand Up @@ -596,7 +600,7 @@ public function isAbsolutePath($file)
{
return strspn($file, '/\\', 0, 1)
|| (strlen($file) > 3 && ctype_alpha($file[0])
&& ':' === substr($file, 1, 1)
&& ':' === $file[1]
&& strspn($file, '/\\', 2, 1)
)
|| null !== parse_url($file, PHP_URL_SCHEME)
Expand Down
10 changes: 9 additions & 1 deletion src/Symfony/Component/Filesystem/Tests/FilesystemTest.php
Expand Up @@ -1103,7 +1103,6 @@ public function providePathsForMakePathRelative()
array('/var/lib/symfony/src/Symfony/', '/var/lib/symfony/src/Symfony/Component/', '../'),
array('/var/lib/symfony/src/Symfony', '/var/lib/symfony/src/Symfony/Component', '../'),
array('/var/lib/symfony/src/Symfony', '/var/lib/symfony/src/Symfony/Component/', '../'),
array('var/lib/symfony/', 'var/lib/symfony/src/Symfony/Component', '../../../'),
array('/usr/lib/symfony/', '/var/lib/symfony/src/Symfony/Component', '../../../../../../usr/lib/symfony/'),
array('/var/lib/symfony/src/Symfony/', '/var/lib/symfony/', 'src/Symfony/'),
array('/aa/bb', '/aa/bb', './'),
Expand Down Expand Up @@ -1145,6 +1144,15 @@ public function providePathsForMakePathRelative()
return $paths;
}

/**
* @group legacy
* @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.
*/
public function testMakePathRelativeWithRelativePaths()
{
$this->assertSame('../../../', $this->filesystem->makePathRelative('var/lib/symfony/', 'var/lib/symfony/src/Symfony/Component'));
}

public function testMirrorCopiesFilesAndDirectoriesRecursively()
{
$sourcePath = $this->workspace.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR;
Expand Down

0 comments on commit 7269013

Please sign in to comment.