/** * Create color profile object from filename. * * @param string $filename * * @throws RuntimeException * * @return $this */ public static function fromFilename($filename) { if (!file_exists($filename) || !is_file($filename) || !is_readable($filename)) { throw new RuntimeException(sprintf('Filename %s is an invalid profile file or is not readable', $filename)); } return new static(StreamUtils::create(StreamUtils::open($filename, 'r'))); }
public function fetch(RequestInterface $request) { $key = $this->getCacheKey($request); $entry = $this->cache->fetch($key); if (!$entry) { return null; } $response = new Response($entry['code'], $entry['headers'], Stream\Utils::create($entry['body'])); $request->getConfig()->set('cache.key', $key); return $response; }
/** * {@inheritdoc} */ public function fetch(FeedInterface $feed, StateInterface $state) { $response = $this->get($feed->getSource(), $this->getCacheKey($feed)); $feed->setSource($response->getEffectiveUrl()); // 304, nothing to see here. if ($response->getStatusCode() == 304) { $state->setMessage($this->t('The feed has not been updated.')); throw new EmptyFeedException(); } // Copy the temp stream to a real file. $download_file = drupal_tempnam('temporary://', 'feeds_http_fetcher'); $dest_stream = Utils::create(fopen($download_file, 'w+')); Utils::copyToStream($response->getBody(), $dest_stream); $response->getBody()->close(); $dest_stream->close(); return new HttpFetcherResult($download_file, $response->getHeaders()); }
public function testProxiesToFactory() { $this->assertEquals('foo', (string) Utils::create('foo')); }
public function fetch(RequestInterface $request) { $key = $this->getCacheKey($request); $entries = $this->cache->fetch($key); if (!$entries) { return null; } $match = $matchIndex = null; $headers = $this->persistHeaders($request); $entries = unserialize($entries); foreach ($entries as $index => $entry) { $vary = isset($entry[1]['vary']) ? $entry[1]['vary'] : ''; if ($this->requestsMatch($vary, $headers, $entry[0])) { $match = $entry; $matchIndex = $index; break; } } if (!$match) { return null; } // Ensure that the response is not expired $response = null; if ($match[4] < time()) { $response = -1; } else { $response = new Response($match[2], $match[1]); if ($match[3]) { if ($body = $this->cache->fetch($match[3])) { $response->setBody(Stream\Utils::create($body)); } else { // The response is not valid because the body was somehow // deleted $response = -1; } } } if ($response === -1) { // Remove the entry from the metadata and update the cache unset($entries[$matchIndex]); if ($entries) { $this->cache->save($key, serialize($entries)); } else { $this->cache->delete($key); } return null; } return $response; }
/** * {@inheritdoc} */ public function getColorProfile() { if (!in_array('icc', $this->imagick->getImageProfiles('*', false))) { return null; } $data = $this->imagick->getImageProfile('icc'); return new ColorProfile(StreamUtils::create($data)); }
/** * {@inheritdoc} */ public function getColorProfile() { try { $data = $this->gmagick->getimageprofile('ICM'); } catch (\GmagickException $exception) { return null; } return new ColorProfile(StreamUtils::create($data)); }