GroupSyncManager
extends Instanceable
in package
Manages registration of GroupSyncInjectors as well as broadcasting group changes to them.
Tags
Table of Contents
Properties
- $_enabled_injectors : array<string|int, GroupSyncInjector>
- $_injectors : array<string|int, GroupSyncInjector>
- $_instances : array<class-string, static>
- Stores instances of classes with their class name as key.
Methods
- broadcastChange() : array<string|int, mixed>
- Execute respective `addGroup()` or `removeGroup()` function on each of the injectors synced to the changed group.
- broadcastGroupChange() : array<string|int, mixed>
- Execute respective `addGroup()` or `removeGroup()` function on each of the injectors (e.g. Nameless itself, Minecraft, Discord) synced to the changed group.
- getColumnNames() : array<string|int, string>
- Get the column name from all injectors, not just enabled ones.
- getEnabledInjectors() : array<string|int, GroupSyncInjector>
- Get all injectors which should be enabled.
- getInjectorByClass() : GroupSyncInjector|null
- Get an enabled `GroupSyncInjector` from its class name, if it exists.
- getInjectors() : array<string|int, GroupSyncInjector>
- Get all the registered injectors.
- getInstance() : static
- Get or make an instance of the class this was called on.
- makeValidator() : Validate
- Create a new `Validate` instance and add the injector defined rules and messages to it.
- registerInjector() : void
- Register a new GroupSyncInjector class.
- registerInjectorColumn() : void
- Add a new column to the `nl2_group_sync` table for this injector to use. Should be called during module initialisation.
- compileValidatorMessages() : array<string, array<string, string>>
- Get an array of column name => validation rule => validation messages array for each of the enabled injectors.
- compileValidatorRules() : array<string, array<string, mixed>>
- Get an array of column name => validation rule array for each of the enabled injectors.
Properties
$_enabled_injectors
private
array<string|int, GroupSyncInjector>
$_enabled_injectors
$_injectors
private
array<string|int, GroupSyncInjector>
$_injectors
= []
$_instances
Stores instances of classes with their class name as key.
private
static array<class-string, static>
$_instances
= []
Methods
broadcastChange()
Execute respective `addGroup()` or `removeGroup()` function on each of the injectors synced to the changed group.
public
broadcastChange(User $user, string $sending_injector_class, array<string|int, mixed> $group_ids) : array<string|int, mixed>
broadcastGroupChange should be used instead. This function has issues, such as that on the first sync it will replace groups on one side with groups from the other side, depending on which side happens to sync first. On the first sync, the desired behaviour is for the new roles on both sides to become the union of roles on both sides.
Parameters
- $user : User
-
NamelessMC user to apply changes to
- $sending_injector_class : string
-
Class name of injector broadcasting this change
- $group_ids : array<string|int, mixed>
-
Array of Group IDs native to the sending injector which were added/removed to the user
Return values
array<string|int, mixed> —Array of logs of changed groups
broadcastGroupChange()
Execute respective `addGroup()` or `removeGroup()` function on each of the injectors (e.g. Nameless itself, Minecraft, Discord) synced to the changed group.
public
broadcastGroupChange(User $user, string $sending_injector_class, array<string|int, mixed> $group_ids_add, array<string|int, mixed> $group_ids_remove) : array<string|int, mixed>
Parameters
- $user : User
-
NamelessMC user to apply changes to
- $sending_injector_class : string
-
Class name of injector broadcasting this change
- $group_ids_add : array<string|int, mixed>
-
Array of injector-native Group IDs were added to the user
- $group_ids_remove : array<string|int, mixed>
-
Array of injector-native Group IDs were removed from the user
Return values
array<string|int, mixed> —Array of logs of changed groups
getColumnNames()
Get the column name from all injectors, not just enabled ones.
public
getColumnNames() : array<string|int, string>
Return values
array<string|int, string> —All column names
getEnabledInjectors()
Get all injectors which should be enabled.
public
getEnabledInjectors() : array<string|int, GroupSyncInjector>
Injectors will only considered be enabled if:
- Their parent module is enabled.
- The
shouldEnable()
method in the injector returns true.
Keeps a cache for the duration of the request incase
any shouldEnable()
method is intensive to execute.
Return values
array<string|int, GroupSyncInjector> —Enabled injectors
getInjectorByClass()
Get an enabled `GroupSyncInjector` from its class name, if it exists.
public
getInjectorByClass(string $class) : GroupSyncInjector|null
Parameters
- $class : string
-
Class name to get injector from
Return values
GroupSyncInjector|null —Instance of injector, null if it doesn't exist or isn't enabled
getInjectors()
Get all the registered injectors.
public
getInjectors() : array<string|int, GroupSyncInjector>
Return values
array<string|int, GroupSyncInjector> —Registered injectors
getInstance()
Get or make an instance of the class this was called on.
public
final static getInstance() : static
Return values
static —Instance of the class this was called on.
makeValidator()
Create a new `Validate` instance and add the injector defined rules and messages to it.
public
makeValidator(array<string|int, mixed> $source, Language $language) : Validate
Parameters
- $source : array<string|int, mixed>
-
Input array to validate, often
$_POST
- $language : Language
-
Language to use for error messages
Return values
Validate —New Validate
instance
registerInjector()
Register a new GroupSyncInjector class.
public
registerInjector(GroupSyncInjector $injector) : void
Ensures the column name of the new injector has not been taken.
Parameters
- $injector : GroupSyncInjector
-
New injector.
registerInjectorColumn()
Add a new column to the `nl2_group_sync` table for this injector to use. Should be called during module initialisation.
public
registerInjectorColumn(GroupSyncInjector $injector) : void
Parameters
- $injector : GroupSyncInjector
-
Injector to add column for.
compileValidatorMessages()
Get an array of column name => validation rule => validation messages array for each of the enabled injectors.
private
compileValidatorMessages(Language $language) : array<string, array<string, string>>
Parameters
- $language : Language
Return values
array<string, array<string, string>>compileValidatorRules()
Get an array of column name => validation rule array for each of the enabled injectors.
private
compileValidatorRules() : array<string, array<string, mixed>>
Return values
array<string, array<string, mixed>> —Array of each enabled injectors array of rules