Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.4] Why do service providers depend on helper functions? #18506

Merged
merged 3 commits into from
Mar 27, 2017
Merged

[5.4] Why do service providers depend on helper functions? #18506

merged 3 commits into from
Mar 27, 2017

Conversation

collegeman
Copy link
Contributor

@collegeman collegeman commented Mar 27, 2017

Dear Taylor and amazing Laravel community;

I'm working on some projects in which it is not possible to rely on core helper functions. The reason for this isn't trivial to explain, but I'll try to be concise. The codebase incorporates more than one Laravel-based application such that it is not possible to use Container::getInstance(), since more than one instance of the Container may exist in a single request.

Because of this constraint, it is also not possible to use the global helper functions, all of which rely on Container::getInstance() for accessing what would normally be the only container in the request.

The simple change I am requesting is that service providers, already having in ServiceProvider::$app the instance of Container that represents their relationship to the application in which they are configured and installed, should use that instance for accessing the Container's contents instead of invoking helper functions.

The specific case I have highlighted below focuses on Illuminate\Mail\MailServiceProvider, but I believe there are other examples, including Illuminate\Database\DatabaseServiceProvider, Illuminate\Pagination\PaginationServiceProvider, and Illuminate\Scout\ScoutServiceProvider.

In addition to ending the practice of using helper functions within service providers, I would like to recommend that the usefulness of being able to pass a subpath argument to resource_path($path='') be refactored into the aliased function Illuminate\Foundation\Application::resourcePath() such that this convenience can continue even without the helper function in play.

Thank you for your consideration.

Sincerely,

Aaron

@taylorotwell taylorotwell merged commit 59bc729 into laravel:5.4 Mar 27, 2017
@collegeman
Copy link
Contributor Author

Yay! <3

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

Successfully merging this pull request may close these issues.

2 participants