Support the ongoing development of Laravel.io →
Configuration
Last updated 2 years ago.
0

Are you using this class as a facade? The facade constructor gets called during service provider registration, and there's no guarantee any of those other facades/services will be loaded or available at that time. From the L5.2 docs on service providers:

Within the register method, you should only bind things into the service container. You should never attempt to register any event listeners, routes, or any other piece of functionality within the register method.

I'm not sure what the rest of your Data class does, but detecting and changing the locale is a global operation that affects more than just Data, so perhaps it would be simpler to exist somewhere else. For example, if you implemented it as a global middleware you could be guaranteed it would run before every controller and still have access to the Cookie and Session values you need.

0

Facades you access via static calls, as they are static proxies. So the constructor doesn't come into play.

0

lagbox said:

Facades you access via static calls, as they are static proxies. So the constructor doesn't come into play.

Not sure if you're responding to me or OP.

If OP: yes I agree, I should've noted that. You shouldn't really try to construct a class you have set up like a facade, as it's very difficult to get the two "paradigms" (singleton with static access and instances with non-static access) to both work well on one class, and I'm not sure why you'd want to.

If me: well the constructor still gets called, except now it's automatically handled behind the scenes, usually by a service provider.

Last updated 8 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

thai6070 thai6070 Joined 18 Apr 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.