master

laravel/framework

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

EnsureRelativePaths.php

TLDR

This file defines a class EnsureRelativePaths in the Illuminate\Console\View\Components\Mutators namespace. The class has an __invoke method that takes a string as a parameter and returns a modified string.

Methods

__invoke

This method ensures that the given string contains only relative paths. If the base_path function exists and the application has a path.base key set, the method removes the base path from the string by replacing it with an empty string. The modified string is then returned.

<?php

namespace Illuminate\Console\View\Components\Mutators;

class EnsureRelativePaths
{
    /**
     * Ensures the given string only contains relative paths.
     *
     * @param  string  $string
     * @return string
     */
    public function __invoke($string)
    {
        if (function_exists('app') && app()->has('path.base')) {
            $string = str_replace(base_path().'/', '', $string);
        }

        return $string;
    }
}