-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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.8] Added hasUser
method to Guard contract;
#25629
Conversation
- laravel#24518 in this PR was added method `hasUser` to the GuardHelper trait. As for me it will be useful to have this method in the contract.
What does this improve in terms of user functionality? |
@taylorotwell , For now, I cannot use the method based on the contract. |
I completely agree with @TBlindaruk . I don't know why Laravel treats contracts like they don't matter and like if all people just use the concrete classes that the framework provides. Also there is the bad practice of just adding new features to point releases and the only reason why some methods don't get added to the contract are to avoid making a breaking change just to avoid to wait (for months) for the feature to land in the next major version. I don't understand then what is the point of having any contract in the framework... @TBlindaruk as Taylor probably won't see this I'd suggest creating a new PR for this, as well as for #25631 |
Not to mention how these PRs get selectively merged, for example #25616 got merged just two days ago. |
@TBlindaruk Thanks for creating contract for my implementation. I also agree with you. |
Please consider who are developing on PhpStorm (with Laravel IDE Helper). Auth::guard()->hasUser(); // PhpStorm Warning: Method hasUser() not found |
@X-Coder264 When I works on a package for Laravel projects, I just requires laravel contracts for dependency injection but I have to call some methods from the concrete classes. It's very bad. I finally decide to use facades because calling some undefined methods of an interface has no meaning. |
@mpyw I think it is not about the developers' tools. It's about the software or code designing. |
@XuanQuynh Using the facade instead of the contract is the same thing as the root service that the facade will resolve from the container implements that same contract. Just because there are some magical docblocks on the facade that document methods that are present only on the concrete implementation doesn't make that any better. And if there is no other way to achieve some functionality other than to use some method that is not on the contract then that is a very good indicator that a method is missing on the contract. Whatever the case, using methods that are not on the contract for a Laravel package is a very bad thing. |
@XuanQuynh Surely I know. I also agree that the following code is contract-based. As a result, PhpStorm can't detect
/**
* Attempt to get the guard from the local cache.
*
* @param string $name
* @return \Illuminate\Contracts\Auth\Guard|\Illuminate\Contracts\Auth\StatefulGuard
*/
public function guard($name = null)
{
$name = $name ?: $this->getDefaultDriver();
return $this->guards[$name] ?? $this->guards[$name] = $this->resolve($name);
} |
hasUser
to the GuardHelper trait. As for me it will be useful to have this method in the contract.