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.8] Added hasUser method to Guard contract; #25629

Closed
wants to merge 1 commit into from

Conversation

TBlindaruk
Copy link
Contributor

 - 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.
@taylorotwell
Copy link
Member

What does this improve in terms of user functionality?

@TBlindaruk
Copy link
Contributor Author

@taylorotwell ,
In case if someone used the contracts instead of the concrete classes then they are available to use this method.

For now, I cannot use the method based on the contract.

@X-Coder264
Copy link
Contributor

X-Coder264 commented Sep 16, 2018

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

@X-Coder264
Copy link
Contributor

Not to mention how these PRs get selectively merged, for example #25616 got merged just two days ago.

@mpyw
Copy link
Contributor

mpyw commented Jan 22, 2019

@TBlindaruk Thanks for creating contract for my implementation. I also agree with you.
@taylorotwell I think it's not bad adding contract on minor update (e.g. 5.7 -> 5.8)

@mpyw
Copy link
Contributor

mpyw commented Jan 22, 2019

@taylorotwell

What does this improve in terms of user functionality?

Please consider who are developing on PhpStorm (with Laravel IDE Helper).

Auth::guard()->hasUser(); // PhpStorm Warning: Method hasUser() not found

@seriquynh
Copy link
Contributor

@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.

@seriquynh
Copy link
Contributor

seriquynh commented Jan 22, 2019

@mpyw I think it is not about the developers' tools. It's about the software or code designing.

@X-Coder264
Copy link
Contributor

@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.

@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.

@mpyw
Copy link
Contributor

mpyw commented Jan 22, 2019

@XuanQuynh Surely I know. I also agree that the following code is contract-based. As a result, PhpStorm can't detect hasUser() method.

Auth::guard()->hasUser()
    /**
     * 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);
    }

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.

5 participants