- Issue created by @gigiabba
- First commit to issue fork.
- Open on Drupal.org →Environment: PHP 8.1 & MySQL 5.7last update
over 1 year ago Not currently mergeable. - @fredysan opened merge request.
- Status changed to Needs review
over 1 year ago 10:01pm 6 July 2023 - last update
over 1 year ago 29,439 pass - @fredysan opened merge request.
- last update
over 1 year ago 29,439 pass - Status changed to RTBC
over 1 year ago 3:57pm 11 July 2023 - 🇺🇸United States smustgrave
Going to mark it but not sure if changing the constructor will be an issue or not. We will see!
- last update
over 1 year ago 29,443 pass - last update
over 1 year ago 29,444 pass - last update
over 1 year ago 29,446 pass - last update
over 1 year ago 29,446 pass - last update
over 1 year ago 29,446 pass - last update
over 1 year ago 29,446 pass - last update
over 1 year ago 29,450 pass - last update
over 1 year ago 29,453 pass - last update
over 1 year ago 29,454 pass - last update
over 1 year ago 29,455 pass - 🇨🇭Switzerland znerol
The issue summary doesn't specify a reason for that change.
In my opinion it is desirable to specify the most narrow type for arguments and return values.
AccountProxyInterface
inherits fromAccountInterface
, hence it is wider. TheAccountProxyInterface
only should be used in places where the additional methods (setAccount()
, etc.) actually get called. It follows that theAccountInterface
is actually the correct type hint for controllers and access checks. - 🇺🇸United States TolstoyDotCom L.A.
The Drupal class uses AccountProxyInterface for currentUser() but the other code I looked at uses AccountInterface. The default current_user service returns an AccountProxyInterface implementation.
In Java, you'd probably want to use AccountProxyInterface as the type hint because if you used AccountInterface but wanted to use one of the AccountProxyInterface you'd need to do a cast (preferably after testing that the object implements AccountProxyInterface).
Is there a reason why the current_user service can't be assumed to implement AccountProxyInterface?
- 🇨🇭Switzerland znerol
When reasoning about which type to choose for a dependency, I suggest to always look at the problem from the consumers view point: E.g., if you implement an access check, or a controller, or some cache context, you choose an interface for your dependency which narrowly matches the requirements of your implementation.
There is no reason why any controller should type hint against
AccountProxyInterface
, since controller code only use theAccountInterface
part of thecurrent_user
service.As for
Drupal::currentUser()
: Unfortunately there is still procedural code (e.g., incore/authorize.php
) which relies on methods of theAccountProxyInterface
. - 🇺🇸United States TolstoyDotCom L.A.
In Java, the current setup would be a bad design.
Apparently the current_user service is generally assumed to be AccountInterface, except for some code which expects AccountProxyInterface. The best solution might be to create two services, one for each interface. They could be implemented using the same Drupal\Core\Session\AccountProxy class. Then, change the code that expects AccountProxyInterface to use that service.
- Status changed to Needs work
over 1 year ago 8:08am 31 July 2023 - 🇬🇧United Kingdom catch
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Session%2...
It is generally more useful to use \Drupal\Core\Session\AccountInterface unless one specifically needs the proxying features of this interface.
#10 sounds reasonable - i.e. try to limit AccountProxyInterface to only the spots it's actually needed and remove the concept from everywhere else.
- 🇫🇷France andypost
There's broader issues
-
UserSession
should gone after 📌 Load user entity in Cookie AuthenticationProvider instead of using manual queries Needs work
-AccountInterface
could be moved 📌 Move AccountInterface out of Session namespace Needs work