public static function addGlobalScope($scope, Closure $implementation = null)
{
if (is_string($scope) && !is_null($implementation)) {
return static::$globalScopes[static::class][$scope] = $implementation;
}
if ($scope instanceof Closure) {
return static::$globalScopes[static::class][spl_object_hash($scope)] = $scope;
}
if ($scope instanceof Scope) {
return static::$globalScopes[static::class][get_class($scope)] = $scope;
}
throw new InvalidArgumentException('Global scope must be an instance of Closure or Scope.');
}