public function ConfigCache::set

Writes a value to a file.

Parameters

string $resource A cache key:

mixed $value A value to cache:

File

drupal/core/vendor/kriswallsmith/assetic/src/Assetic/Cache/ConfigCache.php, line 51

Class

ConfigCache
A config cache stores values using var_export() and include.

Namespace

Assetic\Cache

Code

public function set($resource, $value) {
  $path = $this
    ->getSourcePath($resource);
  if (!is_dir($dir = dirname($path)) && false === @mkdir($dir, 0777, true)) {

    // @codeCoverageIgnoreStart
    throw new \RuntimeException('Unable to create directory ' . $dir);

    // @codeCoverageIgnoreEnd
  }
  if (false === @file_put_contents($path, sprintf("<?php\n\n// {$resource}\nreturn %s;\n", var_export($value, true)))) {

    // @codeCoverageIgnoreStart
    throw new \RuntimeException('Unable to write file ' . $path);

    // @codeCoverageIgnoreEnd
  }
}