As designed Inconsistency: XF\Service\Thread\Creator::setUser() vs. XF\Service\Thread\Replies::setUser()

Affected version
2.0 DP 10


Well-known member
XF\Service\Thread\Creator::setUser() is protected, whereas XF\Service\Thread\Replier::setUser() is public.

This seems inconsistent to me and does make it rather cumbersome to post a new thread as a specific user:
$creator = \XF::asVisitor($user, function() use ($forum)
	return \XF::service('XF:Thread\Creator', $forum);
instead of just
$creator = \XF::service('XF:Thread\Creator', $forum);

Chris D

XenForo developer
Staff member
It's deliberate.

A bunch of other services (like the Replier) are now structured in the same was as the Creator service (which was finished after the release of DP10).

Your first example is exactly the approach that should be taken.

It's important to ensure that the user cannot change during the lifetime of the service, as that could result in some unexpected behaviour. With that in mind, the setUser method shouldn't be public, and the user should be set and stored based on the visitor User entity when the service is instantiated. If there's a need to run the service as a different user, that can be done using the asVisitor function.