/** * @param IrcDataObject $message * @return void */ public function sniffLinks(IrcDataObject $message) { $string = $message->getParams()['text']; $target = $message->getTargets()[0]; try { $uri = SnifferHelper::extractUriFromString($string); } catch (NoUriFoundException $e) { return; } $cacheItem = $this->uriCache->getCacheItem($uri); if (!$cacheItem) { try { $shortUri = $this->createShortUri($uri); # We prefer is.gd for content type queries. This significantly reduces errors. $contentTypeUri = $shortUri; if ($contentTypeUri == 'No short url') { $contentTypeUri = $uri; } $content_type = SnifferHelper::getContentTypeFromUri($contentTypeUri); $title = '(not a web page, content type: ' . $content_type . ')'; if ($content_type == 'text/html') { $title = SnifferHelper::getTitleFromUri($uri); } } catch (PageTitleDoesNotExistException $e) { $title = '(Page title not found or empty. Put that in your pipe and smoke it.)'; } catch (ContentTypeNotFoundException $e) { return; } catch (GuzzleException $e) { $title = '(link was unresponsive: ' . $uri . ')'; } if (!empty($title) && !empty($shortUri)) { $this->uriCache->addCacheItem($uri, $title, $shortUri); } } else { $title = $cacheItem->getTitle(); $shortUri = $cacheItem->getShortUri(); } if (empty($shortUri) || empty($title)) { return; } $connection = $this->getModule('Connection'); $connection->write($connection->getGenerator()->ircNotice($target, '[' . $shortUri . '] ' . $title)); }
public function testExpireEntry() { $uriCache = new UriCache(); $cacheItem = $uriCache->addCacheItem('someUriDest', 'someUri'); // Set the expiry time to the past. $cacheItem->setExpireTime(time() - 1); // getCacheItem will return false if the item has expired. $returnedCacheItem = $uriCache->getCacheItem('someUriDest'); $this->assertEquals(false, $returnedCacheItem); }