-
Notifications
You must be signed in to change notification settings - Fork 59
/
Registry.php
33 lines (27 loc) · 866 Bytes
/
Registry.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
namespace SilverStripe\GraphQL\Schema\BulkLoader;
use Psr\Container\NotFoundExceptionInterface;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Injector\Injector;
/**
* Frontend for creating a cached registry instance based on all the qualifying subclasses.
*/
class Registry
{
private static ?RegistryBackend $inst = null;
/**
* @return RegistryBackend
*/
public static function inst(): RegistryBackend
{
if (self::$inst) {
return self::$inst;
}
$subclasses = array_values(ClassInfo::subclassesFor(AbstractBulkLoader::class, false) ?? []);
$bulkLoaders = array_map(function ($className) {
return Injector::inst()->get($className);
}, $subclasses ?? []);
self::$inst = RegistryBackend::create(...$bulkLoaders);
return self::$inst;
}
}