master

laravel/framework

Last updated at: 29/12/2023 09:22

functions.php

TLDR

This functions.php file provides a function join_paths to join multiple paths together.

Methods

join_paths

This function takes in a base path and an array of paths, and joins them together into a single path. It removes any leading slashes in the paths and adds a directory separator between the paths. The resulting path is then returned.

Classes

<?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, ...$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);
    }
}