AvatarKitAvatarServiceDiscovery.php in Avatar Kit 8.2
File
src/AvatarKitAvatarServiceDiscovery.php
View source
<?php
namespace Drupal\avatars;
use dpi\ak\Annotation\AvatarService;
use dpi\ak\AvatarKit\AvatarServices\AvatarServiceInterface;
use dpi\ak\AvatarServiceDiscovery;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Cache\UseCacheBackendTrait;
class AvatarKitAvatarServiceDiscovery extends AvatarServiceDiscovery {
use UseCacheBackendTrait;
protected $classLoader;
protected $cacheBackend;
public function __construct($class_loader, CacheBackendInterface $cache_backend) {
$this->subdir = 'AvatarKit/AvatarServices/';
$this->serviceInterface = AvatarServiceInterface::class;
$this->annotationClass = AvatarService::class;
$this->cacheBackend = $cache_backend;
$cache_key = 'avatars_ak_service_annotations';
$annotations = $this
->cacheGet($cache_key)->data ?? NULL;
if (!isset($annotations)) {
$root_namespaces = $class_loader
->getPrefixesPsr4();
$classes = $this
->discoverClasses($root_namespaces);
$annotations = $this
->discoverAnnotations($classes);
$this
->cacheSet($cache_key, $annotations, Cache::PERMANENT);
}
$this->annotations = $annotations;
}
}