本文整理汇总了PHP中Nette\Environment::getCache方法的典型用法代码示例。如果您正苦于以下问题:PHP Environment::getCache方法的具体用法?PHP Environment::getCache怎么用?PHP Environment::getCache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Environment
的用法示例。
在下文中一共展示了Environment::getCache方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setLocale
public function setLocale($lang)
{
switch ($lang) {
case 'en':
setlocale(LC_ALL, 'en_EN.UTF8', 'en_EN.UTF-8', 'en_EN ');
break;
case 'cs':
default:
setlocale(LC_ALL, 'cs_CZ.UTF8', 'cs_CZ.UTF-8', 'cs_CZ');
}
$this->lang = $lang;
$cache = Environment::getCache();
$cacheName = 'getText-' . $this->lang;
if (isset($cache[$cacheName])) {
$this->dictionary = unserialize($cache[$cacheName]);
} else {
$dict = new Model\Dictionary('utils/translate');
try {
$this->dictionary = $dict->getPairs($this->lang);
$cache->save($cacheName, serialize((array) $this->dictionary), array('expire' => time() + 60 * 30, 'refresh' => TRUE, 'tags' => array('dictionary')));
} catch (DibiException $e) {
echo $e;
}
}
}
示例2: log_write
function log_write($data, FileDownload $file, IDownloader $downloader)
{
$cache = Environment::getCache("FileDownloader/log");
$log = array();
$tid = (string) $file->getTransferId();
if (!isset($cache["registry"])) {
$cache["registry"] = array();
}
$reg = $cache["registry"];
$reg[$tid] = true;
$cache["registry"] = $reg;
if (isset($cache[$tid])) {
$log = $cache[$tid];
}
Debugger::fireLog("Data: " . $data . "; " . $downloader->end);
$data = $data . ": " . Helpers::bytes($file->transferredBytes) . " <->; ";
if ($downloader instanceof AdvancedDownloader and $downloader->isInitialized()) {
$data .= "position: " . Helpers::bytes($downloader->position) . "; ";
//$data .= "length: ".Helpers::bytes($downloader->length)."; ";
$data .= "http-range: " . Helpers::bytes($downloader->start) . "-" . Helpers::bytes($downloader->end) . "; ";
$data .= "progress (con: " . round($file->transferredBytes / $downloader->end * 100) . "% X ";
$data .= "file: " . round($downloader->position / $file->sourceFileSize * 100) . "%)";
}
$log[] = $data;
$cache[$tid] = $log;
}
示例3: createValidator
public static function createValidator()
{
$loader = new Validator\Mapping\Loader\AnnotationLoader();
$cache = Environment::isProduction() ? new ValidatorCache(Environment::getCache("SymfonyValidator")) : null;
$metadataFactory = new Validator\Mapping\ClassMetadataFactory($loader, $cache);
$validatorFactory = new Validator\ConstraintValidatorFactory();
$validator = new Validator\Validator($metadataFactory, $validatorFactory);
return $validator;
}
示例4: getConfig
/**
* Get table config
* @return Config
*/
public function getConfig()
{
if (empty($this->config)) {
$cacheKey = get_class($this) . "-" . $this->table . "-" . $this->rowClass;
$cache = Environment::getCache("Ormion");
if (isset($cache[$cacheKey])) {
$this->config = $cache[$cacheKey];
} else {
$tableInfo = $this->getDb()->getDatabaseInfo()->getTable($this->table);
$this->config = Config::fromTableInfo($tableInfo);
$cache[$cacheKey] = $this->config;
}
}
return $this->config;
}
示例5: onFlush
public function onFlush(Event\OnFlushEventArgs $args)
{
$em = $args->getEntityManager();
$uow = $em->getUnitOfWork();
$tags = array();
foreach ($uow->getScheduledEntityDeletions() as $entity) {
$tags[] = get_class($entity);
$tags[] = $entity->getCacheKey();
}
foreach ($uow->getScheduledEntityUpdates() as $entity) {
$tags[] = get_class($entity);
$tags[] = $entity->getCacheKey();
}
Environment::getCache()->clean(array(Cache::TAGS => array_unique($tags)));
}
示例6: getMimeType
/**
* Tries to find out the mimetype for file specified in param.
* The query is based on file extension. If system contains mime_content_type
* function it takes precedence. If no match is found the application/octet-stream
* is returned.
*
* @param string path to file
* @param string|null fiele extension, if null it will be taken as last .part in filepath
*/
static function getMimeType($filepath, $extension = null)
{
if (function_exists("mime_content_type")) {
$mime = mime_content_type($filepath);
if (self::isValidMimeType($mime)) {
return $mime;
}
}
$cache = Nette\Environment::getCache("vBuilder.Download");
if (!isset($cache["mime-types"])) {
$m = parse_ini_file(__DIR__ . '/' . self::MIME_INI_FILEPATH);
if ($m != false) {
$cache["mime-types"] = $m;
}
}
if ($extension == null) {
$extension = pathinfo($filepath, PATHINFO_EXTENSION);
}
if (array_key_exists($extension, $cache["mime-types"])) {
$mime = $cache["mime-types"][$extension];
}
return self::isValidMimeType($mime) ? $mime : "application/octet-stream";
}
示例7: handleTrashDeleteOne
public function handleTrashDeleteOne($id)
{
if ($id > 0) {
$item = $this->items->fetch($id);
if (!$item) {
$this->flashMessage('There is no file to delete', 'info');
$this->redirect('default');
} else {
try {
if (file_exists(FILESTORAGE_DIR . '/' . $item['filename'])) {
unlink(FILESTORAGE_DIR . '/' . $item['filename']);
}
if (file_exists(TEMP_DIR . '/imagecache/' . $id)) {
$this->deltree(TEMP_DIR . '/imagecache/' . $id);
}
} catch (Exception $e) {
$this->flashMessage('Brutal error on the disk!', 'err');
}
$this->items->delete($id);
$this->flashMessage('The file has been completely deleted.', 'ok');
}
} else {
$this->flashMessage('Missing ID of file!', 'err');
}
$cache = Environment::getCache();
$cache->clean(array('tags' => array('photogallery', 'files', 'filesystem')));
}
示例8: getRolesToSelect
public function getRolesToSelect()
{
$cache = Environment::getCache('application/acl');
$cacheName = 'roles_to_select';
if (isset($cache[$cacheName])) {
return unserialize($cache[$cacheName]);
} else {
$roles = dibi::query("\n\t SELECT [r.name] AS [role_name], if(!ISNULL([r.note]),CONCAT([r.name],' - ',[r.note]),[r.name]) AS [ident]\n\t FROM [users_roles] AS [r] LEFT JOIN [users_roles] AS [rp] ON [r.parent_id] = [rp.id]\n\t ORDER BY [r.id] ASC;");
$roles = $roles->fetchPairs('role_name', 'ident');
$cache->save($cacheName, serialize((array) $roles), array('expire' => time() + 60 * 60 * 30, 'refresh' => TRUE, 'tags' => array('system', 'acl')));
return $roles;
}
}
示例9: getPanel
/**
* Renders HTML code for custom panel.
* @return string
* @see IDebugPanel::getPanel()
*/
public function getPanel()
{
if ($this->response instanceof \Nette\Application\Responses\ForwardResponse || $this->response instanceof \Nette\Application\Responses\RedirectResponse) {
return '';
}
/** @var Template */
$template = new FileTemplate();
$template->setFile(dirname(__FILE__) . "/bar.latte");
$template->registerFilter(new Engine());
$template->presenter = $template->control = $template->rootComponent = Environment::getApplication()->getPresenter();
if ($template->presenter === NULL) {
return NULL;
}
$template->wrap = static::$wrap;
$template->cache = static::$cache ? Environment::getCache('Debugger.Panels.ComponentTree') : NULL;
$template->dumps = static::$dumps;
$template->parametersOpen = static::$parametersOpen;
$template->presenterOpen = static::$presenterOpen;
$template->showSources = static::$showSources;
$template->omittedVariables = static::$omittedTemplateVariables;
$template->registerHelper('parametersInfo', callback($this, 'getParametersInfo'));
$template->registerHelper('editlink', callback($this, 'buildEditorLink'));
$template->registerHelper('highlight', callback($this, 'highlight'));
$template->registerHelper('filterMethods', callback($this, 'filterMethods'));
$template->registerHelper('renderedTemplates', callback($this, 'getRenderedTemplates'));
$template->registerHelper('isPersistent', callback($this, 'isPersistent'));
$template->registerHelperLoader('Nette\\Templating\\Helpers::loader');
ob_start();
$template->render();
return ob_get_clean();
}
示例10: clearCache
/**
* Remove cached html from cache
* @param IRecord record
*/
public function clearCache(IRecord $record)
{
$cache = Environment::getCache(__NAMESPACE__ . "-" . __CLASS__ . "-" . get_class($record) . "-" . $this->name);
$key = $record->getPrimary();
unset($cache[$key]);
}
示例11: getCache
/**
* Get cache
*
* @param string $namespace nella namespace suffix
* @return Nette\Caching\Cache
*/
public static function getCache($namespace = NULL)
{
return \Nette\Environment::getCache($namespace ? "ActiveMapper." . $namespace : "ActiveMapper");
}
示例12: getCache
/**
* @return Nette\Caching\Cache
*/
protected static function getCache()
{
return Nette\Environment::getCache('Nette.Annotations');
}
示例13: getGlobalCategoriesArray
public function getGlobalCategoriesArray($type, $hidden = false, $zero = false)
{
$cache = Environment::getCache('application/system');
$cacheName = 'category_to_select/' . $type . '/' . $hidden;
if (isset($cache[$cacheName])) {
return unserialize($cache[$cacheName]);
} else {
$res = dibi::select('[id], [name]')->from('[category] [c]')->where($type . ' = 1')->orderBy('name');
if (!$hidden) {
$res->where('visible', '=', '1');
}
$res = $res->fetchPairs('id', 'name');
if ($zero) {
$a = array(0 => '---');
$res = $a + $res;
}
$cache->save($cacheName, serialize((array) $res), array('expire' => time() + 60 * 60 * 30, 'refresh' => TRUE, 'tags' => array('system', 'category', $type)));
return $res;
}
}
示例14: __construct
public function __construct()
{
$this->data = Environment::getCache('Doctrine');
}
示例15: console
<?php
use Nette\Environment;
Environment::getHttpResponse()->setHeader("refresh", "1");
$cache = Environment::getCache("FileDownloader/log");
echo "<html><body>";
echo "<h1>Log console (called events)</h1>";
echo "<p>Clear log = delete temp files</p>";
echo "<style>p{font-size: 11px;font-family: monospace;}</style>";
$reg = $cache["registry"];
$y = 0;
if (count($reg) > 0) {
krsort($reg);
foreach ($reg as $tid => $none) {
$y++;
$tid = (string) $tid;
$log = $cache[$tid];
$i = 0;
if (count($log) > 0) {
krsort($log);
foreach ($log as $key => $val) {
if ($i == 0) {
echo "<h2>Con. #" . $tid;
if (strstr($val, "Abort")) {
echo " <span style=\"color: orange;\">(Aborted)</span>";
} elseif (strstr($val, "Lost")) {
echo " <span style=\"color: red;\">(Connection losted)</span>";
} elseif (strstr($val, "Complete")) {
echo " <span style=\"color: green;\">(Completed)</span>";
} else {
echo " (Running)";