Пример #1
0
 /**
  * Checks if cHash is required for the current request and calls
  * TypoScriptFrontendController::reqCHash() if so.
  * This call will trigger a PageNotFoundException if arguments are required and cHash is not present.
  *
  * @param Request $request
  * @param string $pluginNamespace
  */
 public function enforceForRequest(Request $request, string $pluginNamespace)
 {
     $arguments = $request->getArguments();
     if (is_array($arguments) && count($arguments) > 0) {
         $parameters = [$pluginNamespace => $arguments];
         $parameters['id'] = $this->typoScriptFrontendController->id;
         $relevantParameters = $this->cacheHashCalculator->getRelevantParameters(http_build_query($parameters));
         if (count($relevantParameters) > 0) {
             $this->typoScriptFrontendController->reqCHash();
         }
     }
 }
 /**
  * @dataProvider canSkipParametersWithEmptyValuesDataprovider
  * @test
  */
 public function canSkipParametersWithEmptyValues($params, $settings, $expected)
 {
     $this->fixture->setConfiguration($settings);
     $actual = $this->fixture->getRelevantParameters($params);
     $this->assertEquals($expected, array_keys($actual));
 }
 /**
  * Calculates a hash string based on additional parameters in the url.
  *
  * Calculated hash is stored in $this->cHash_array.
  * This is used to cache pages with more parameters than just id and type.
  *
  * @return void
  * @see reqCHash()
  */
 public function makeCacheHash()
 {
     // No need to test anything if caching was already disabled.
     if ($this->no_cache && !$this->TYPO3_CONF_VARS['FE']['pageNotFoundOnCHashError']) {
         return;
     }
     $GET = GeneralUtility::_GET();
     if ($this->cHash && is_array($GET)) {
         $this->cHash_array = $this->cacheHash->getRelevantParameters(GeneralUtility::implodeArrayForUrl('', $GET));
         $cHash_calc = $this->cacheHash->calculateCacheHash($this->cHash_array);
         if ($cHash_calc != $this->cHash) {
             if ($this->TYPO3_CONF_VARS['FE']['pageNotFoundOnCHashError']) {
                 $this->pageNotFoundAndExit('Request parameters could not be validated (&cHash comparison failed)');
             } else {
                 $this->disableCache();
                 $this->getTimeTracker()->setTSlogMessage('The incoming cHash "' . $this->cHash . '" and calculated cHash "' . $cHash_calc . '" did not match, so caching was disabled. The fieldlist used was "' . implode(',', array_keys($this->cHash_array)) . '"', 2);
             }
         }
     } elseif (is_array($GET)) {
         // No cHash is set, check if that is correct
         if ($this->cacheHash->doParametersRequireCacheHash(GeneralUtility::implodeArrayForUrl('', $GET))) {
             $this->reqCHash();
         }
     }
 }