Statics, consts and singletons are considered a bad practice because they obstruct testing, and create a maintenance problem due to references in various places. In a mini-framework for websites, I am running into these problems and want to replace the statics, but don't know the best alternative in one use case.
This use case is illustrated by a permissions system based on groups: for a client C to have access to data item X, a group name in C's array of authorization group names must match one in X's array of "required" names.
Comparisons ("does the client have this auth?") can be easily abstracted out to a dynamic calls. But when assigning a group name to a client, or assigning a "required" group name on a data item, how can I refer to them individually and police that each is from a centrally defined set, without statics?
Current code looks like:
$client->appendAuzGroupName( Tokens::AUZ_GRP_PUBLIC );
-- with Tokens loading values from a config file at each cache refresh.
Searching here and on the web has turned up a lot of advice against static/const/singleton, but the only idea I've found on replacing them is "use IoC / DI". However, taking these values via params only moves the problem to a different place in the code.
I'm open to changing to another auth system design, but it must have this level of granularity, and listing usernames (ACL design) seems unlikely to be practical at scale.