Rick Sinders
Rick Sinders

Reputation: 43

How exactly does Laravel make class alias possible?

What I mean is, how is it you can access the Validator facade without using the FQN in a controller?

Ie, why does validator::make work, not requiring illuminate\blah\facades\validator::make()

How is this accomplished from a PHP standpoint? FYI, I'm not interested in how to alias a class through Laravel's App class, but rather the mechanics of it. Is it done through a custom autoloading function...?

Upvotes: 4

Views: 1129

Answers (2)

Marcin Nabiałek
Marcin Nabiałek

Reputation: 111829

To be precise it's implemented in:

\vendor\laravel\framework\src\Illuminate\Foundation\AliasLoader.php

file, using class_alias() function as @user3158900 mentioned:

public function load($alias)
{
    if (isset($this->aliases[$alias]))
    {
        return class_alias($this->aliases[$alias], $alias);
    }
}

Upvotes: 3

user1669496
user1669496

Reputation: 33058

I believe it is accomplished through the class_alias() function.

http://php.net/manual/en/function.class-alias.php

Upvotes: 1

Related Questions