/**
  * @param string $identifier
  * @param \Callable $callback
  * @return mixed
  */
 public function get($identifier, $callback)
 {
     if ($this->cache->has($identifier)) {
         return $this->cache->get($identifier);
     }
     $value = $callback();
     $this->cache->set($identifier, $value);
     return $value;
 }
示例#2
0
 /**
  * Returns banners for the given parameters if given Hmac validation succeeds
  *
  * @param string $categories
  * @param string $startingPoint
  * @param string $displayMode
  * @param int $currentPageUid
  * @param string $hmac
  * @return string
  */
 public function getBannersAction($categories = '', $startingPoint = '', $displayMode = 'all', $currentPageUid = 0, $hmac = '')
 {
     $compareString = $currentPageUid . $categories . $startingPoint . $displayMode;
     if ($this->hashService->validateHmac($compareString, $hmac)) {
         /** @var \DERHANSEN\SfBanners\Domain\Model\BannerDemand $demand */
         $demand = $this->objectManager->get('DERHANSEN\\SfBanners\\Domain\\Model\\BannerDemand');
         $demand->setCategories($categories);
         $demand->setStartingPoint($startingPoint);
         $demand->setDisplayMode($displayMode);
         $demand->setCurrentPageUid($currentPageUid);
         /* Get banners */
         $banners = $this->bannerRepository->findDemanded($demand);
         /* Update Impressions */
         $this->bannerRepository->updateImpressions($banners);
         /* Collect identifier based on uids for all banners */
         $ident = $GLOBALS['TSFE']->id . $GLOBALS['TSFE']->sys_language_uid;
         foreach ($banners as $banner) {
             $ident .= $banner->getUid();
         }
         $ret = $this->cacheInstance->get(sha1($ident));
         if ($ret === false || $ret === null) {
             $this->view->assign('banners', $banners);
             $this->view->assign('settings', $this->settings);
             $ret = $this->view->render();
             // Save value in cache
             $this->cacheInstance->set(sha1($ident), $ret, array('sf_banners'), $this->settings['cacheLifetime']);
         }
     } else {
         $ret = LocalizationUtility::translate('wrong_hmac', 'SfBanners');
     }
     return $ret;
 }
示例#3
0
 /**
  * Actual function to generate the rootline and cache it
  *
  * @throws \RuntimeException
  * @return void
  */
 protected function generateRootlineCache()
 {
     $page = $this->getRecordArray($this->pageUid);
     // If the current page is a mounted (according to the MP parameter) handle the mount-point
     if ($this->isMountedPage()) {
         $mountPoint = $this->getRecordArray($this->parsedMountPointParameters[$this->pageUid]);
         $page = $this->processMountedPage($page, $mountPoint);
         $parentUid = $mountPoint['pid'];
         // Anyhow after reaching the mount-point, we have to go up that rootline
         unset($this->parsedMountPointParameters[$this->pageUid]);
     } else {
         $parentUid = $page['pid'];
     }
     $cacheTags = array('pageId_' . $page['uid']);
     if ($parentUid > 0) {
         // Get rootline of (and including) parent page
         $mountPointParameter = !empty($this->parsedMountPointParameters) ? $this->mountPointParameter : '';
         /** @var $rootline \TYPO3\CMS\Core\Utility\RootlineUtility */
         $rootline = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Utility\RootlineUtility::class, $parentUid, $mountPointParameter, $this->pageContext);
         $rootline = $rootline->get();
         // retrieve cache tags of parent rootline
         foreach ($rootline as $entry) {
             $cacheTags[] = 'pageId_' . $entry['uid'];
             if ($entry['uid'] == $this->pageUid) {
                 throw new \RuntimeException('Circular connection in rootline for page with uid ' . $this->pageUid . ' found. Check your mountpoint configuration.', 1343464103);
             }
         }
     } else {
         $rootline = array();
     }
     array_push($rootline, $page);
     krsort($rootline);
     static::$cache->set($this->cacheIdentifier, $rootline, $cacheTags);
     static::$localCache[$this->cacheIdentifier] = $rootline;
 }
 /**
  * Builds and caches the proxy files
  *
  * @return void
  * @throws Exception
  */
 public function build()
 {
     $extensibleExtensions = $this->getExtensibleExtensions();
     $entities = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extensionKey]['entities'];
     foreach ($entities as $entity) {
         $key = 'Domain/Model/' . $entity;
         // Get the file from static_info_tables itself, this needs to be loaded as first
         $path = ExtensionManagementUtility::extPath($this->extensionKey) . 'Classes/' . $key . '.php';
         if (!is_file($path)) {
             throw new Exception('given file "' . $path . '" does not exist');
         }
         $code = $this->parseSingleFile($path, FALSE);
         // Get the files from all other extensions that are extending this domain model class
         if (isset($extensibleExtensions[$key]) && is_array($extensibleExtensions[$key]) && count($extensibleExtensions[$key]) > 0) {
             $extensionsWithThisClass = array_keys($extensibleExtensions[$key]);
             foreach ($extensionsWithThisClass as $extension) {
                 $path = ExtensionManagementUtility::extPath($extension) . 'Classes/' . $key . '.php';
                 if (is_file($path)) {
                     $code .= $this->parseSingleFile($path);
                 }
             }
         }
         // Close the class definition and the php tag
         $code = $this->closeClassDefinition($code);
         // The file is added to the class cache
         $entryIdentifier = str_replace('/', '', $key);
         try {
             $this->cacheInstance->set($entryIdentifier, $code);
         } catch (Exception $e) {
             throw new Exception($e->getMessage());
         }
     }
 }
 /**
  * Register the given brush for deferred loading.
  *
  * @param AbstractBrush $brush
  *
  * @return void
  */
 public function handle(AbstractBrush $brush)
 {
     $brushes = [];
     $aliases = [];
     if ($this->cache->has('brushes')) {
         $brushes = (array) $this->cache->get('brushes');
     }
     if (isset($brushes[$brush->identifier])) {
         $aliases = (array) $brushes[$brush->identifier];
     }
     $aliasKeys = array_flip($aliases);
     if (!isset($aliasKeys[$brush->alias])) {
         array_push($aliases, $brush->alias);
     }
     $brushes[$brush->identifier] = $aliases;
     $this->cache->set('brushes', $brushes);
 }
示例#6
0
 /**
  * cache resource
  *
  * @param $resource
  * @return void
  */
 protected function cacheResource($resource)
 {
     if (!empty($resource)) {
         $cacheKey = $this->getCacheIdentifierForPath($resource['path']);
         if (!$this->cache->has($cacheKey)) {
             if (!$resource['is_dir']) {
                 $this->cache->set($cacheKey, $resource);
             }
         }
     }
 }
 public function geoJSONAction()
 {
     $geoJson = '{}';
     if (is_numeric($uid = GeneralUtility::_GP('uid'))) {
         // Don't return anything, not even cached entry, if the map is not in the repository
         if (!is_null($map = $this->mapRepository->findByIdentifier($uid))) {
             if ($GLOBALS['TSFE']->sys_page->versioningPreview) {
                 $geoJson = $this->geoJSONService->generateFeatureCollectionGeoJSON($map->getFeatures());
             } else {
                 if ($this->frontend->get($uid) == FALSE) {
                     $geoJson = $this->geoJSONService->generateFeatureCollectionGeoJSON($map->getFeatures());
                     $this->frontend->set($uid, $geoJson);
                 } else {
                     $geoJson = $this->frontend->get($uid);
                 }
             }
         }
     }
     return $geoJson;
 }
 /**
  * Start password reset
  *
  * @param string $username Username of a user
  * @return void
  *
  * @validate $username NotEmpty
  */
 public function startPasswordResetAction($username)
 {
     $user = $this->frontendUserRepository->findOneByUsername($username);
     // Forbid password reset if there is no password or password property,
     // e.g. if the user has not completed a special registration process
     // or is supposed to authenticate in some other way
     $password = ObjectAccess::getPropertyPath($user, 'password');
     if ($password === NULL) {
         $this->logger->error('Failed to initiate password reset for user "' . $username . '": no password present');
         $this->addLocalizedFlashMessage('resetPassword.failed.nopassword', NULL, FlashMessage::ERROR);
         $this->redirect('showPasswordResetForm');
     }
     $hash = md5(GeneralUtility::generateRandomBytes(64));
     $token = array('uid' => $user->getUid(), 'hmac' => $this->hashService->generateHmac($password));
     $tokenLifetime = $this->getSettingValue('passwordReset.token.lifetime');
     // Remove possibly existing reset tokens and store new one
     $this->tokenCache->flushByTag($user->getUid());
     $this->tokenCache->set($hash, $token, array($user->getUid()), $tokenLifetime);
     $expiryDate = new \DateTime(sprintf('now + %d seconds', $tokenLifetime));
     $hashUri = $this->uriBuilder->setTargetPageUid($this->getSettingValue('passwordReset.page'))->setUseCacheHash(FALSE)->setCreateAbsoluteUri(TRUE)->uriFor('showPasswordResetForm', array('hash' => $hash));
     /** @var \PAGEmachine\Hairu\Domain\DTO\PasswordResetRequestTransferObject $passwordResetRequestTransferObject */
     $passwordResetRequestTransferObject = GeneralUtility::makeInstance('PAGEmachine\\Hairu\\Domain\\DTO\\PasswordResetRequestTransferObject');
     $passwordResetRequestTransferObject->setUser($user);
     $passwordResetRequestTransferObject->setHash($hash);
     $passwordResetRequestTransferObject->setHashUri($hashUri);
     $passwordResetRequestTransferObject->setExpiryDate($expiryDate);
     $actionVariables = array('user' => $user, 'hash' => $hash, 'hashUri' => $hashUri, 'expiryDate' => $expiryDate);
     $this->view->assignMultiple($actionVariables);
     /** @var \TYPO3\CMS\Core\Mail\MailMessage $message */
     $message = $this->objectManager->get('TYPO3\\CMS\\Core\\Mail\\MailMessage');
     $message->setFrom($this->getSettingValue('passwordReset.mail.from'))->setTo($user->getEmail())->setSubject($this->getSettingValue('passwordReset.mail.subject'));
     $this->request->setFormat('txt');
     $message->setBody($this->view->render('passwordResetMail'), 'text/plain');
     $this->request->setFormat('html');
     $message->addPart($this->view->render('passwordResetMail'), 'text/html');
     $mailSent = FALSE;
     $passwordResetRequestTransferObject->setMessage($message);
     $this->emitBeforePasswordResetMailSendSignal($passwordResetRequestTransferObject);
     try {
         $mailSent = $message->send();
     } catch (\Swift_SwiftException $e) {
         $this->logger->error($e->getMessage());
     }
     if ($mailSent) {
         $this->addLocalizedFlashMessage('resetPassword.started', NULL, FlashMessage::INFO);
     } else {
         $this->addLocalizedFlashMessage('resetPassword.failed.sending', NULL, FlashMessage::ERROR);
     }
     $this->redirect('showPasswordResetForm');
 }
 /**
  * Writes to cache.
  *
  * @param string                $cacheIdentifier
  * @param ErrorHandlerInterface $errorHandler
  */
 public function set($cacheIdentifier, ErrorHandlerInterface $errorHandler)
 {
     $tags = (array) $errorHandler->getCacheTags();
     $data = json_encode(array('class' => get_class($errorHandler), 'data' => $errorHandler->getCachingData()));
     $this->cacheInstance->set($cacheIdentifier, $data, $tags);
 }
 /**
  * Puts the generated dataArray into the workspace cache.
  *
  * @param array $versions All records uids etc. First key is table name, second key incremental integer. Records are associative arrays with uid and t3ver_oid fields. The pid of the online record is found as "livepid" the pid of the offline record is found in "wspid
  * @param string $filterTxt The given filter text from the grid.
  */
 protected function setDataArrayIntoCache(array $versions, $filterTxt)
 {
     $hash = $this->calculateHash($versions, $filterTxt);
     $this->workspacesCache->set($hash, $this->dataArray, array($this->currentWorkspace, 'user_' . $GLOBALS['BE_USER']->user['uid']));
 }
示例#11
0
 /**
  * Sets the data for the given cache entry identifier
  *
  * @param string $entryIdentifier Cache entry identifier
  * @param mixed $data Data for the cache entry
  * @param array $tags Cache tags
  * @param int $lifetime Lifetime of the cache entry
  *
  * @return void
  */
 public function set($entryIdentifier, $data, array $tags = [], $lifetime = null)
 {
     $this->cache->set($entryIdentifier, $data, $tags, $lifetime);
 }
示例#12
0
 /**
  * Store coordinate for hash in cache table
  *
  * @param string $key
  * @param array $value
  *
  * @return void
  */
 public function setValueInCacheTable($key, $value)
 {
     $this->cacheFrontend->set($key, $value);
 }
示例#13
0
 /**
  * Write a value to the first and second level cache.
  *
  * @param string $cacheId
  * @param mixed $value
  */
 public function set($cacheId, $value)
 {
     $this->setToFirstLevelCache($cacheId, $value);
     $this->secondLevelCache->set($cacheId, $value);
 }
示例#14
0
 /**
  * @param string $identifier
  * @param string $content
  * @return void
  */
 protected function setToCache($identifier, $content)
 {
     $this->cache->set($identifier, $content);
 }
 public function setCached($url, $content)
 {
     $this->cache->set($this->calculateCacheIdentifier($url), $content, array(), $this->seconds);
     return $this->isCached($url);
 }
示例#16
0
 public function set($identifier, $value, array $tags = array(), $lifetime = NULL)
 {
     $this->cacheInstance->set($identifier, $value, $tags, $lifetime);
 }