-
-
Notifications
You must be signed in to change notification settings - Fork 40
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
Create interface for User #20
Comments
User is registered in DIC as a service with the name therefore it should be possible to replace it with your own implementation similarly like in this thread. |
Problem is, there is User class used directly in Nette code. If not in code, definitelly in comments which isn't good for IDE. |
My tip: don't use the |
@JanTvrdik Thanks for the tip, but this doesn't solve issue in framework. User is somehow hardcoded and it would be great if it wasn't. I'm happy to make PR (or at least try it), but I want to know others opinions first. |
@foxycode Actually the User class is problematic in quite a few use-cases so in advanced systems it's better to not use it at all. Rather than a PR it's better to just make your own library like I did. |
@enumag Again, why not solve it directly in framework? Yes, I can make my own library. I actually already did. I believe, if we put our heads together, we can solve it directly in framework. I train new programmers in Nette and it's confusing for them. I can't simply tell them to write own library :) |
Yes, but it is an interface of a class with bad name and bad design. The goal should be to remove (or somehow fix?) the class instead of making even more stuff dependent on in. |
@JanTvrdik Ok, I agree with it :) I'd like to try, but need to know what others don't like about User class. Can you tell your opinion? |
Few random things that are bad about the User class.
|
God, I just wanted to post the same as @foxycode. I am upgrading a larger codebase from nette v 2.4 and it's just not possible, since we are using an extended version of So... how do we extend the functionality of In particular, in my case I have some custom logic in |
Hi, any updates on this topic? It's quite old, but still it is a issue when upgrading large codebase from v2 |
I've just came accross this. I want NOT to use While I agree that
@dg Could you please write some thoughts to this old issue? At least for me, a big blocker NOT to make PRs is the fact, that I'll never know if the whole stuff wouldn't be rejected. And I don't want to/can't waste my time. If you say "well, yes, let's do it this way, would someone do it?", I believe more people would contribute. Edit: just realized that non final |
In case the interface is too much to ask or simply not desired, I suggest also removing the return type hint, so that the overriding methods can return anything, not descendants of the // Presenter.php
/**
* @return Nette\Security\User
*/
public function getUser() //: Nette\Security\User
{
if (!$this->user) {
throw new Nette\InvalidStateException('Service User has not been set.');
}
return $this->user;
} This is a backwards-compatible <10 minute fix. |
Simple, stop using it at all. Only hard which is to how to remove it from DI, so nobody can wire it. I have approached it using this fake factory overriding original registration from nette/security di-extension. services:
security.user:
factory: CampApp\App\Infrastructure\NoNetteUserFactory::throwErrorWhenAccessed()
autowired: false final class NoNetteUserFactory
{
public static function throwErrorWhenAccessed(): User
{
throw new UsageException('Hey! Nette\User is disabled in this project (as interface does not match use-cases needed in this project). Use <YourClass> instead.');
}
} |
Wouldn't it then be better to completely remove it from |
Few times I wanted to use own
User
implementation, bt there is no simple way how to force Nette to use it. I'd like to haveIUser
same way asIUserStorage
to be able to use my own implementation in framework.The text was updated successfully, but these errors were encountered: