芝麻web文件管理V1.00
编辑当前文件:/home/mgatv524/cms.mgaplay.com.br/lib/Widget/IcsTrait.php
. */ namespace Xibo\Widget; use GuzzleHttp\Client; use GuzzleHttp\Exception\RequestException; use Stash\Invalidation; use Xibo\Support\Exception\ConfigurationException; trait IcsTrait { /** * Get the feed from Cache or Source * @return bool|string * @throws ConfigurationException */ private function getFeed() { // Create a key to use as a caching key for this item. // the rendered feed will be cached, so it is important the key covers all options. $feedUrl = urldecode($this->getOption('uri')); if (empty($feedUrl)) { throw new ConfigurationException(__('Please provide a calendar feed URL')); } /** @var \Stash\Item $cache */ $cache = $this->getPool()->getItem($this->makeCacheKey(md5($feedUrl))); $cache->setInvalidationMethod(Invalidation::SLEEP, 5000, 15); $this->getLog()->debug('Calendar ' . $feedUrl . '. Cache key: ' . $cache->getKey()); // Get the document out of the cache $document = $cache->get(); // Check our cache to see if the key exists if ($cache->isMiss()) { // Invalid local cache $this->getLog()->debug('Cache Miss, getting ICS file'); // Lock this cache item (120 seconds) $cache->lock(120); try { // Create a Guzzle Client to get the Feed XML $client = new Client(); $response = $client->get($feedUrl, $this->getConfig()->getGuzzleProxy([ 'timeout' => 20 // wait no more than 20 seconds: https://github.com/xibosignage/xibo/issues/1401 ])); $document = $response->getBody()->getContents(); } catch (RequestException $requestException) { // Log and return empty? $this->getLog()->error('Unable to get feed: ' . $requestException->getMessage()); $this->getLog()->debug($requestException->getTraceAsString()); throw new ConfigurationException(__('Unable to download feed')); } // Add this to the cache. $cache->set($document); $cache->expiresAfter($this->getOption('updateInterval', 360) * 60); // Save $this->getPool()->saveDeferred($cache); } else { $this->getLog()->debug('Feed returned from Cache'); } return $document; } }