8000 moved makePathRelative to Filesystem · symfony/symfony@258a1fd · GitHub
[go: up one dir, main page]

Skip to content

Commit 258a1fd

Browse files
committed
moved makePathRelative to Filesystem
1 parent 8cb0cc6 commit 258a1fd

File tree

2 files changed

+27
-28
lines changed

2 files changed

+27
-28
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8686
$filesystem->remove($targetDir);
8787

8888
if ($input->getOption('symlink')) {
89-
$relativeOriginDir = $this->makePathRelative($originDir, realpath($bundlesDir));
89+
$relativeOriginDir = $filesystem->makePathRelative($originDir, realpath($bundlesDir));
9090
$filesystem->symlink($relativeOriginDir, $targetDir);
9191
} else {
9292
$filesystem->mkdir($targetDir, 0777);
@@ -96,31 +96,4 @@ protected function execute(InputInterface $input, OutputInterface $output)
9696
}
9797
}
9898
}
99-
100-
/**
101-
* Given an existing path, convert it to a path relative to a given starting path
102-
*
103-
* @var string Absolute path of target
104-
* @var string Absolute path where traversal begins
105-
* @return string Path of target relative to starting path
106-
*/
107-
protected function makePathRelative($endPath, $startPath)
108-
{
109-
// Find for which character the the common path stops
110-
$offset = 0;
111-
while ($startPath[$offset] === $endPath[$offset]) {
112-
$offset++;
113-
}
114-
115-
// Determine how deep the start path is relative to the common path (ie, "web/bundles" = 2 levels)
116-
$depth = substr_count(substr($startPath, $offset), DIRECTORY_SEPARATOR) + 1;
117-
118-
// Repeated "../" for each level need to reach the common path
119-
$traverser = str_repeat('../', $depth);
120-
121-
// Construct $endPath from traversing to the common path, then to the remaining $endPath
122-
$relativePath = $traverser.substr($endPath, $offset);
123-
124-
return $relativePath;
125-
}
12699
}

src/Symfony/Component/HttpKernel/Util/Filesystem.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,32 @@ public function symlink($originDir, $targetDir, $copyOnWindows = false)
168168
}
169169
}
170170

171+
/**
172+
* Given an existing path, convert it to a path relative to a given starting path
173+
*
174+
* @var string Absolute path of target
175+
* @var string Absolute path where traversal begins
176+
*
177+
* @return string Path of target relative to starting path
178+
*/
179+
public function makePathRelative($endPath, $startPath)
180+
{
181+
// Find for which character the the common path stops
182+
$offset = 0;
183+
while ($startPath[$offset] === $endPath[$offset]) {
184+
$offset++;
185+
}
186+
187+
// Determine how deep the start path is relative to the common path (ie, "web/bundles" = 2 levels)
188+
$depth = substr_count(substr($startPath, $offset), DIRECTORY_SEPARATOR) + 1;
189+
190+
// Repeated "../" for each level need to reach the common path
191+
$traverser = str_repeat('../', $depth);
192+
193+
// Construct $endPath from traversing to the common path, then to the remaining $endPath
194+
return $traverser.substr($endPath, $offset);
195+
}
196+
171197
/**
172198
* Mirrors a directory to another.
173199
*

0 commit comments

Comments
 (0)
0