Skip to content
This repository has been archived by the owner on Apr 7, 2021. It is now read-only.

Import facades directly instead of importing the aliases #17

Merged
merged 1 commit into from
May 19, 2018

Conversation

funkjedi
Copy link
Contributor

Updated to import the facades directly instead of importing the aliases.

Allows package to be used without having to include the alias. Also prevents package from breaking if Laravel specific aliases (Log, Cache, Config, etc...) have been removed from config/app.php.

@austinheap
Copy link
Owner

Hey @funkjedi, what's the motivation behind this? If someone is using a different Facade for Log/Cache/etc then wouldn't this bypass it?

@funkjedi
Copy link
Contributor Author

That's exactly the scenario we want to avoid. For example if a Laravel app defines the following class:

// doesn't implement \Psr\Log\LoggerInterface like we
// are expecting when we use \Log expecting it to be a facade
class Log {
	public function send() {
		//
	}
}

Because it exists in the global namespace the class alias for the Log facade won't be created by Laravel.

If it was someones intention to actually replace a facade what they'd actually do is replace the underlying binding in the service container. That way when accessed via facade, helpers (i.e. info(), logger(), etc) or by using the service binding (i.e. App::make('log'), app('log'), etc) it's alway using the same implementation.

@austinheap austinheap merged commit 4ce8e8c into austinheap:master May 19, 2018
@austinheap
Copy link
Owner

Thanks @funkjedi!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants