/** * Gets an access token from the user, caching via the configured cache file. * * @param \Symfony\Component\Console\Input\InputInterface $input The command input. * @param \Guywithnose\ReleaseNotes\Prompt\PromptFactory $promptFactory The prompt factory. * @return string The github access token. */ private function _getToken(InputInterface $input, PromptFactory $promptFactory) { $token = $input->getOption('access-token'); if ($token) { return $token; } $cache = new Cache($input->getOption('cache-dir')); return trim($cache->getOrCreate($input->getOption('token-file'), [], $promptFactory->create('Please enter a github access token'))); }
<?php include '../autoload.php'; use Gregwar\Cache\Cache; $cache = new Cache(); $data = $cache->getOrCreate('uppercase.txt', array('younger-than' => 'original.txt'), function () { echo "Generating file...\n"; return strtoupper(file_get_contents('original.txt')); }); echo $data;
<?php include '../autoload.php'; // If using composer use Gregwar\Cache\Cache; $cache = new Cache(); $cache->setCacheDirectory('cache'); // This is the default // If the cache exists, this will return it, else, the closure will be called // to create this image $data = $cache->getOrCreate('red-square.png', array(), function ($filename) { $i = imagecreatetruecolor(100, 100); imagefill($i, 0, 0, 0xff0000); file_put_contents($filename, 'abc'); imagepng($i, $filename); }); header('Content-type: image/png'); echo $data;
/** * [categories description] * @param [type] $selected [description] * @return [type] [description] */ public function categories() { $cache = new Cache(); $cache->setCacheDirectory($this->cacheDir); $data = $cache->getOrCreate('google-feed-taxonomy.txt', array('max-age' => '860400'), function () { return file_get_contents("http://www.google.com/basepages/producttype/taxonomy.en-GB.txt"); }); return explode("\n", trim($data)); }
/** * Retrieve Google product categories from internet and cache the result * @param string $languageISO639 * @return array */ public function categories($languageISO639 = 'gb') { //map two letter language to culture $languageMap = array('au' => 'en-AU', 'br' => 'pt-BR', 'cn' => 'zh-CN', 'cz' => 'cs-CZ', 'de' => 'de-DE', 'dk' => 'da-DK', 'es' => 'es-ES', 'fr' => 'fr-FR', 'gb' => 'en-GB', 'it' => 'it-IT', 'jp' => 'ja-JP', 'nl' => 'nl-NL', 'no' => 'no-NO', 'pl' => 'pl-PL', 'ru' => 'ru-RU', 'sw' => 'sv-SE', 'tr' => 'tr-TR', 'us' => 'en-US'); //set default language to gb for backward compatibility $languageCulture = $languageMap['gb']; if (array_key_exists($languageISO639, $languageMap)) { $languageCulture = $languageMap[$languageISO639]; } var_dump($languageISO639, $languageCulture); $cache = new Cache(); $cache->setCacheDirectory($this->cacheDir); $data = $cache->getOrCreate('google-feed-taxonomy.' . $languageISO639 . '.txt', array('max-age' => '86400'), function () use($languageCulture) { return file_get_contents("http://www.google.com/basepages/producttype/taxonomy." . $languageCulture . ".txt"); }); return explode("\n", trim($data)); }