You are here

public static function AvatarKitEntityHooks::preventRecursion in Avatar Kit 8.2

Wrapper utility to prevent recursion.

Parameters

string $bin: A key to prevent collisions with any other active callers of this utility.

callable $keyGen: A callable which will take $args, and return a unique string key.

callable $recur: A callable which will take $args, which will run if it is already not already being executed further up the calling stack. This method returns void.

array $args: An arbitrary array of values to pass to $keyGen and $recur callables.

1 call to AvatarKitEntityHooks::preventRecursion()
AvatarKitEntityHooks::storageLoad in src/AvatarKitEntityHooks.php
Implements hook_entity_storage_load().

File

src/AvatarKitEntityHooks.php, line 87

Class

AvatarKitEntityHooks
Drupal entity hooks.

Namespace

Drupal\avatars

Code

public static function preventRecursion(string $bin, callable $keyGen, callable $recur, array $args) : void {
  static $static = [];
  if (!isset($static[$bin])) {
    $static[$bin] = [];
  }
  $key = $keyGen(...$args);
  if (!in_array($key, $static[$bin])) {
    $static[$bin][$key] = TRUE;
    $recur(...$args);
    unset($static[$bin][$key]);
  }
}