master

laravel/framework

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

ViewName.php

TLDR

The provided file, ViewName.php, contains a class called ViewName. This class has a static method called normalize that normalizes a given view name.


Methods

normalize

normalize($name)

This method takes in a string parameter called $name and normalizes it. If the $name does not contain the delimiter ViewFinderInterface::HINT_PATH_DELIMITER, it replaces all occurrences of / with . in the $name and returns the result.

If the $name contains the delimiter, it splits the $name into $namespace and $name by exploding it at the delimiter. It then replaces all occurrences of / with . in the $name and returns the concatenation of $namespace, delimiter, and the normalized $name.


<?php

namespace Illuminate\View;

class ViewName
{
    /**
     * Normalize the given view name.
     *
     * @param  string  $name
     * @return string
     */
    public static function normalize($name)
    {
        $delimiter = ViewFinderInterface::HINT_PATH_DELIMITER;

        if (! str_contains($name, $delimiter)) {
            return str_replace('/', '.', $name);
        }

        [$namespace, $name] = explode($delimiter, $name);

        return $namespace.$delimiter.str_replace('/', '.', $name);
    }
}