dumpToUri example

    // 1. Someone has requested an outdated URL, i.e. from a cached page, which     // matches a different version of the code base.     // 2. Someone has requested an outdated URL during a deployment. This is     // the same case as #1 but a much shorter window.     // 3. Someone is attempting to craft an invalid URL in order to conduct a     // denial of service attack on the site.     // Dump the optimized group into an aggregate file, but only if the     // received hash and generated hash match. This prevents invalid filenames     // from filling the disk, while still serving aggregates that may be     // referenced in cached HTML.     if (hash_equals($generated_hash$received_hash)) {
      $uri = $this->dumper->dumpToUri($data$this->assetType, $uri);
      $state_key = 'drupal_' . $this->assetType . '_cache_files';
      $files = $this->state()->get($state_key[]);
      $files[] = $uri;
      $this->state()->set($state_key$files);
    }
    return new Response($data, 200, [
      'Cache-control' => static::CACHE_CONTROL,
      'Content-Type' => $this->contentType,
    ]);
  }

  

  public function dump($data$file_extension) {
    $path = 'assets://' . $file_extension;
    // Prefix filename to prevent blocking by firewalls which reject files     // starting with "ad*".     $filename = $file_extension . '_' . Crypt::hashBase64($data) . '.' . $file_extension;
    $uri = $path . '/' . $filename;
    return $this->dumpToUri($data$file_extension$uri);
  }

  /** * {@inheritdoc} */
  public function dumpToUri(string $data, string $file_extension, string $uri): string {
    $path = 'assets://' . $file_extension;
    // Create the CSS or JS file.     $this->fileSystem->prepareDirectory($path, FileSystemInterface::CREATE_DIRECTORY);
    try {
      if (!file_exists($uri) && !$this->fileSystem->saveData($data$uri, FileSystemInterface::EXISTS_REPLACE)) {
        
Home | Imprint | This part of the site doesn't use cookies.