/** * @param $tag * @param $query * @return mixed * @throws \Desarrolla2\Cache\Exception\FileCacheException */ public function cache($tag, $query) { $adapter = new File(__DIR__ . '/../../../../../../src/Storage/cache'); $adapter->setOption('ttl', $this->duration); $cache = new Cache($adapter); $cache->set($tag, $query, $this->duration); return $cache->get($tag); }
/** * Get an instance of the cache helper * @return Desarrolla2\Cache\Cache */ public function cache_driver() { if (!$this->_cache) { $adapter = new DCache_Adapter\File(realpath(__DIR__ . '../../../' . static::CACHE_DIR)); $adapter->setOption('ttl', static::CACHE_LIFETIME); $this->_cache = new DCache\Cache($adapter); } return $this->_cache; }
public static function write($arreglo, $root, $archivo) { if (!self::$instance instanceof self) { self::$instance = new self(); } $_xml = new \SimpleXMLElement("<?xml version=\"1.0\"?><" . $root . "></" . $root . ">"); self::array_to_xml($arreglo, $_xml); $adapter = new File(PATH_CACHE); $adapter->setOption('ttl', 86400); $cache = new Cache($adapter); $cache->set('config', $arreglo, 86400); return $_xml->asXML($archivo); }
private function __construct() { $adapter = new File(PATH_CACHE); $adapter->setOption('ttl', 8640000); $this->cache = new Cache($adapter); if (is_null($this->cache->get('translations'))) { $translations = []; $available = array_slice(scandir(PATH_LOCALE), 2); foreach ($available as $locale) { $data = file(PATH_LOCALE . '/' . $locale); foreach ($data as $_trans) { $translations[basename($locale, ".dat")][] = explode('|', $_trans); } } $this->cache->set('translations', $translations, 8640000); } }
private function __construct() { $adapter = new File(PATH_CACHE); $adapter->setOption('ttl', 86400); $this->cache = new Cache($adapter); if (is_null($this->cache->get('config'))) { $file = PATH_CONFIG . "/config.xml"; if (file_exists(PATH_CONFIG . "/config_local.xml")) { $file = PATH_CONFIG . "/config_local.xml"; } if (!file_exists($file)) { $_config = array(); } else { $_config = self::xml2array(new \SimpleXMLElement(file_get_contents($file))); $this->cache->set('config', $_config, 86400); } } }
private function _token($type) { if ($type == 'Generic') { $adapter = new File(PATH_CACHE); $adapter->setOption('ttl', 10800); $cache = new Cache($adapter); $token = $cache->get('token'); if (is_null($token)) { $token = Tokenizer::create(['GENERIC_API' => true], APP_KEY, 180); $cache->set('token', $token, 10800); } return $token; } if ($type == 'User') { //var_dump(Session::get()); return Session::get('sincco\\login\\token'); } }
/** * Create a cache to store the broker session id. * * @return Cache */ protected function createCacheAdapter() { $adapter = new Adapter\File('/tmp'); $adapter->setOption('ttl', 10 * 3600); return new Cache($adapter); }
function buildChain($cert, $certPath, $includeRoot = false) { if (isExpired($cert)) { throw new Exception("Certificate has expired"); } if (areCertsLinked($cert, $cert)) { throw new Exception("Self-signed or CA cert"); } $uris = $cert["issuers"]; if (!$uris) { throw new Exception("Certificate doesn't specify issuers"); } $c = $cert; $chain = []; while (sizeof($uris) > 0) { $old = $c; $uri = array_shift($uris); $path = downloadIssuer($uri); list($inform, $format) = detectCertFormat($path); $c = parseFormattedCert(readCertificate($path, $inform, $format)); if (isExpired($c)) { throw new Exception("Expired intermediate in the chain"); } if (areCertsLinked($c, $c)) { break; } if (!areCertsLinked($c, $old)) { $msg = "Intermediate doesn't match previous certificate in the chain"; throw new Exception($msg); } $chain[] = $path; if (isset($c["issuers"])) { foreach ($c["issuers"] as $i) { $uris[] = $i; // we don't currently have a good way of handling multiple // issuers break; } } } // we are at the end of the chain, see if there's matching root CA $cacheDir = __DIR__ . '/cache'; $adapter = new File($cacheDir); $adapter->setOption('ttl', 600); $cache = new Cache($adapter); if (!$cache->get(md5($path) . "-root")) { $root = findMatchingRoot($c); $chain[] = $root; $cache->set(md5($path) . "-root", $root); } else { $chain[] = $cache->get(md5($path) . "-root"); } // build certificate bundle foreach ($chain as $i => $path) { list($inform, $format) = detectCertFormat($path); $cmd = sprintf("openssl x509 -inform %s -outform pem -in %s -out %s", escapeshellarg($inform), escapeshellarg($path), escapeshellarg(__DIR__ . "/tmp/" . sha1($cert["subject"]) . "-{$i}.pem")); exec($cmd); } unlink(__DIR__ . "/tmp/bundle.crt"); foreach ($chain as $i => $path) { file_put_contents(__DIR__ . "/tmp/bundle.crt", file_get_contents(__DIR__ . "/tmp/" . sha1($cert["subject"]) . "-{$i}.pem"), FILE_APPEND); } // verify the chain is valid $cmd = sprintf("openssl verify -verbose -purpose sslserver -CAfile %s/tmp/bundle.crt %s", __DIR__, escapeshellarg($certPath)); try { execute($cmd); } catch (Exception $e) { $err = implode("\n", $e->output); throw new Exception("Can't verify the bundle: {$err}"); } // extract the original cert (it might contain some, or all, parts of the // chain already) $cmd = sprintf("openssl x509 -inform pem -outform pem -in %s", $certPath); $out = implode("\n", execute($cmd)); $out .= "\n"; if (!$includeRoot) { array_pop($chain); } foreach ($chain as $i => $path) { $out .= file_get_contents(__DIR__ . "/tmp/" . sha1($cert["subject"]) . "-{$i}.pem"); unlink(__DIR__ . "/tmp/" . sha1($cert["subject"]) . "-{$i}.pem"); } return $out; }
/** * Create a cache to store the broker session id. * * @return Cache */ protected function createCacheAdapter() { $adapter = new Adapter\File($this->options['files_cache_directory']); $adapter->setOption('ttl', $this->options['files_cache_ttl']); return new Cache($adapter); }
<?php session_start(); require_once 'vendor/autoload.php'; // Setup caching use Desarrolla2\Cache\Cache; use Desarrolla2\Cache\Adapter\File as FileCache; $adapter = new FileCache('cache'); $adapter->setOption('ttl', 3600); $adapter = new Desarrolla2\Cache\Adapter\NotCache(); $cache = new Cache($adapter); // Gather the data $crawler = new Ratb\Scraper($cache); dump($crawler->getLines());