|
|
|
@ -46,33 +46,22 @@ class ReferenceManager implements IReferenceManager { |
|
|
|
|
/** @var IReferenceProvider[]|null */ |
|
|
|
|
private ?array $providers = null; |
|
|
|
|
private ICache $cache; |
|
|
|
|
private Coordinator $coordinator; |
|
|
|
|
private ContainerInterface $container; |
|
|
|
|
private LinkReferenceProvider $linkReferenceProvider; |
|
|
|
|
private LoggerInterface $logger; |
|
|
|
|
private IConfig $config; |
|
|
|
|
private IUserSession $userSession; |
|
|
|
|
|
|
|
|
|
public function __construct(LinkReferenceProvider $linkReferenceProvider, |
|
|
|
|
ICacheFactory $cacheFactory, |
|
|
|
|
Coordinator $coordinator, |
|
|
|
|
ContainerInterface $container, |
|
|
|
|
LoggerInterface $logger, |
|
|
|
|
IConfig $config, |
|
|
|
|
IUserSession $userSession) { |
|
|
|
|
$this->linkReferenceProvider = $linkReferenceProvider; |
|
|
|
|
|
|
|
|
|
public function __construct( |
|
|
|
|
private LinkReferenceProvider $linkReferenceProvider, |
|
|
|
|
ICacheFactory $cacheFactory, |
|
|
|
|
private Coordinator $coordinator, |
|
|
|
|
private ContainerInterface $container, |
|
|
|
|
private LoggerInterface $logger, |
|
|
|
|
private IConfig $config, |
|
|
|
|
private IUserSession $userSession, |
|
|
|
|
) { |
|
|
|
|
$this->cache = $cacheFactory->createDistributed('reference'); |
|
|
|
|
$this->coordinator = $coordinator; |
|
|
|
|
$this->container = $container; |
|
|
|
|
$this->logger = $logger; |
|
|
|
|
$this->config = $config; |
|
|
|
|
$this->userSession = $userSession; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Extract a list of URLs from a text |
|
|
|
|
* |
|
|
|
|
* @param string $text |
|
|
|
|
* @return string[] |
|
|
|
|
*/ |
|
|
|
|
public function extractReferences(string $text): array { |
|
|
|
@ -85,9 +74,6 @@ class ReferenceManager implements IReferenceManager { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Try to get a cached reference object from a reference string |
|
|
|
|
* |
|
|
|
|
* @param string $referenceId |
|
|
|
|
* @return IReference|null |
|
|
|
|
*/ |
|
|
|
|
public function getReferenceFromCache(string $referenceId): ?IReference { |
|
|
|
|
$matchedProvider = $this->getMatchedProvider($referenceId); |
|
|
|
@ -102,9 +88,6 @@ class ReferenceManager implements IReferenceManager { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Try to get a cached reference object from a full cache key |
|
|
|
|
* |
|
|
|
|
* @param string $cacheKey |
|
|
|
|
* @return IReference|null |
|
|
|
|
*/ |
|
|
|
|
public function getReferenceByCacheKey(string $cacheKey): ?IReference { |
|
|
|
|
$cached = $this->cache->get($cacheKey); |
|
|
|
@ -118,9 +101,6 @@ class ReferenceManager implements IReferenceManager { |
|
|
|
|
/** |
|
|
|
|
* Get a reference object from a reference string with a matching provider |
|
|
|
|
* Use a cached reference if possible |
|
|
|
|
* |
|
|
|
|
* @param string $referenceId |
|
|
|
|
* @return IReference|null |
|
|
|
|
*/ |
|
|
|
|
public function resolveReference(string $referenceId): ?IReference { |
|
|
|
|
$matchedProvider = $this->getMatchedProvider($referenceId); |
|
|
|
@ -148,7 +128,6 @@ class ReferenceManager implements IReferenceManager { |
|
|
|
|
* Try to match a reference string with all the registered providers |
|
|
|
|
* Fallback to the link reference provider (using OpenGraph) |
|
|
|
|
* |
|
|
|
|
* @param string $referenceId |
|
|
|
|
* @return IReferenceProvider|null the first matching provider |
|
|
|
|
*/ |
|
|
|
|
private function getMatchedProvider(string $referenceId): ?IReferenceProvider { |
|
|
|
@ -169,10 +148,6 @@ class ReferenceManager implements IReferenceManager { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Get a hashed full cache key from a key and prefix given by a provider |
|
|
|
|
* |
|
|
|
|
* @param IReferenceProvider $provider |
|
|
|
|
* @param string $referenceId |
|
|
|
|
* @return string |
|
|
|
|
*/ |
|
|
|
|
private function getFullCacheKey(IReferenceProvider $provider, string $referenceId): string { |
|
|
|
|
$cacheKey = $provider->getCacheKey($referenceId); |
|
|
|
@ -183,10 +158,6 @@ class ReferenceManager implements IReferenceManager { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Remove a specific cache entry from its key+prefix |
|
|
|
|
* |
|
|
|
|
* @param string $cachePrefix |
|
|
|
|
* @param string|null $cacheKey |
|
|
|
|
* @return void |
|
|
|
|
*/ |
|
|
|
|
public function invalidateCache(string $cachePrefix, ?string $cacheKey = null): void { |
|
|
|
|
if ($cacheKey === null) { |
|
|
|
|