-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[10.x] Move
Illuminate\Foundation\Application::joinPaths()
to `Illu…
…minate\Filesystem\join_paths()` (#49433) * Move `Illuminate\Foundation\Application::joinPaths()` to `Illuminate\Filesystem\join_paths()` Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com> * wip Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com> * wip Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com> * wip Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com> * formatting --------- Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com> Co-authored-by: Taylor Otwell <taylor@laravel.com>
- Loading branch information
1 parent
6c5af17
commit 26281bd
Showing
6 changed files
with
74 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Illuminate\Filesystem; | ||
|
||
if (! function_exists('Illuminate\Filesystem\join_paths')) { | ||
/** | ||
* Join the given paths together. | ||
* | ||
* @param string|null $basePath | ||
* @param string ...$paths | ||
* @return string | ||
*/ | ||
function join_paths($basePath, string ...$paths) | ||
{ | ||
foreach ($paths as $index => $path) { | ||
if (empty($path)) { | ||
unset($paths[$index]); | ||
} else { | ||
$paths[$index] = DIRECTORY_SEPARATOR.ltrim($path, DIRECTORY_SEPARATOR); | ||
} | ||
} | ||
|
||
return $basePath.implode('', $paths); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Filesystem; | ||
|
||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\Attributes\RequiresOperatingSystem; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
use function Illuminate\Filesystem\join_paths; | ||
|
||
class JoinPathsHelperTest extends TestCase | ||
{ | ||
#[RequiresOperatingSystem('Linux|DAR')] | ||
#[DataProvider('unixDataProvider')] | ||
public function testItCanMergePathsForUnix(string $expected, string $given) | ||
{ | ||
$this->assertSame($expected, $given); | ||
} | ||
|
||
public static function unixDataProvider() | ||
{ | ||
yield ['app/Http/Kernel.php', join_paths('app', 'Http', 'Kernel.php')]; | ||
yield ['app/Http/Kernel.php', join_paths('app', '', 'Http', 'Kernel.php')]; | ||
} | ||
|
||
#[RequiresOperatingSystem('Windows')] | ||
#[DataProvider('windowsDataProvider')] | ||
public function testItCanMergePathsForWindows(string $expected, string $given) | ||
{ | ||
$this->assertSame($expected, $given); | ||
} | ||
|
||
public static function windowsDataProvider() | ||
{ | ||
yield ['app\Http\Kernel.php', join_paths('app', 'Http', 'Kernel.php')]; | ||
yield ['app\Http\Kernel.php', join_paths('app', '', 'Http', 'Kernel.php')]; | ||
} | ||
} |