Logic for loading and storing user options (aka preferences) should live in a dedicated service. Methods to be factored out of the User class include:
We'll probably want a UserPreferences class that defines a value object that holds user preferences, and a UserPreferencesStore to return these:
- getDefaultPreferences(): UserPreferences;
- loadPreferences( UserIdentity $id ): UserPreferences;
- savePreferences( UserIdentity $id, UserPreferences $pref );
UserPreferencesStore should cache options locally, but the cache can be very small (3 objects or something), since in nearly all cases, the only preferences needed are the ones for the user who is requesting the page. Alternatively, the service could be hard coded to only load and save the current user's preferences, or it could know the current user's name, and cache only the preferences associated with that user. Thinking this further, we may want to set up this service in a way that makes it impossible to access or modify another user's preferences during a web request, and reserve such activities to maintenance scripts.
Caveat: A PreferencesFactory service exists, but it constructs *forms*, and should probably be renamed to PreferencesUIFactory or some such.