Skip to content

Commit 26281bd

Browse files
[10.x] Move Illuminate\Foundation\Application::joinPaths() to Illuminate\Filesystem\join_paths() (#49433)
* Move `Illuminate\Foundation\Application::joinPaths()` to `Illuminate\Filesystem\join_paths()` Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * formatting --------- Signed-off-by: Mior Muhammad Zaki <[email protected]> Co-authored-by: Taylor Otwell <[email protected]>
1 parent 6c5af17 commit 26281bd

File tree

6 files changed

+74
-3
lines changed

6 files changed

+74
-3
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
"files": [
128128
"src/Illuminate/Collections/helpers.php",
129129
"src/Illuminate/Events/functions.php",
130+
"src/Illuminate/Filesystem/functions.php",
130131
"src/Illuminate/Foundation/helpers.php",
131132
"src/Illuminate/Support/helpers.php"
132133
],

src/Illuminate/Console/MigrationGeneratorCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use Illuminate\Filesystem\Filesystem;
66
use Illuminate\Support\Composer;
77

8+
use function Illuminate\Filesystem\join_paths;
9+
810
abstract class MigrationGeneratorCommand extends Command
911
{
1012
/**
@@ -114,7 +116,7 @@ protected function replaceMigrationPlaceholders($path, $table)
114116
protected function migrationExists($table)
115117
{
116118
return count($this->files->glob(
117-
$this->laravel->joinPaths($this->laravel->databasePath('migrations'), '*_*_*_*_create_'.$table.'_table.php')
119+
join_paths($this->laravel->databasePath('migrations'), '*_*_*_*_create_'.$table.'_table.php')
118120
)) !== 0;
119121
}
120122
}

src/Illuminate/Filesystem/composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
"autoload": {
2525
"psr-4": {
2626
"Illuminate\\Filesystem\\": ""
27-
}
27+
},
28+
"files": [
29+
"functions.php"
30+
]
2831
},
2932
"extra": {
3033
"branch-alias": {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Illuminate\Filesystem;
4+
5+
if (! function_exists('Illuminate\Filesystem\join_paths')) {
6+
/**
7+
* Join the given paths together.
8+
*
9+
* @param string|null $basePath
10+
* @param string ...$paths
11+
* @return string
12+
*/
13+
function join_paths($basePath, string ...$paths)
14+
{
15+
foreach ($paths as $index => $path) {
16+
if (empty($path)) {
17+
unset($paths[$index]);
18+
} else {
19+
$paths[$index] = DIRECTORY_SEPARATOR.ltrim($path, DIRECTORY_SEPARATOR);
20+
}
21+
}
22+
23+
return $basePath.implode('', $paths);
24+
}
25+
}

src/Illuminate/Foundation/Application.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
3030
use Symfony\Component\HttpKernel\HttpKernelInterface;
3131

32+
use function Illuminate\Filesystem\join_paths;
33+
3234
class Application extends Container implements ApplicationContract, CachesConfiguration, CachesRoutes, HttpKernelInterface
3335
{
3436
use Macroable;
@@ -586,7 +588,7 @@ public function viewPath($path = '')
586588
*/
587589
public function joinPaths($basePath, $path = '')
588590
{
589-
return $basePath.($path != '' ? DIRECTORY_SEPARATOR.ltrim($path, DIRECTORY_SEPARATOR) : '');
591+
return join_paths($basePath, $path);
590592
}
591593

592594
/**
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Illuminate\Tests\Filesystem;
4+
5+
use PHPUnit\Framework\Attributes\DataProvider;
6+
use PHPUnit\Framework\Attributes\RequiresOperatingSystem;
7+
use PHPUnit\Framework\TestCase;
8+
9+
use function Illuminate\Filesystem\join_paths;
10+
11+
class JoinPathsHelperTest extends TestCase
12+
{
13+
#[RequiresOperatingSystem('Linux|DAR')]
14+
#[DataProvider('unixDataProvider')]
15+
public function testItCanMergePathsForUnix(string $expected, string $given)
16+
{
17+
$this->assertSame($expected, $given);
18+
}
19+
20+
public static function unixDataProvider()
21+
{
22+
yield ['app/Http/Kernel.php', join_paths('app', 'Http', 'Kernel.php')];
23+
yield ['app/Http/Kernel.php', join_paths('app', '', 'Http', 'Kernel.php')];
24+
}
25+
26+
#[RequiresOperatingSystem('Windows')]
27+
#[DataProvider('windowsDataProvider')]
28+
public function testItCanMergePathsForWindows(string $expected, string $given)
29+
{
30+
$this->assertSame($expected, $given);
31+
}
32+
33+
public static function windowsDataProvider()
34+
{
35+
yield ['app\Http\Kernel.php', join_paths('app', 'Http', 'Kernel.php')];
36+
yield ['app\Http\Kernel.php', join_paths('app', '', 'Http', 'Kernel.php')];
37+
}
38+
}

0 commit comments

Comments
 (0)