You are here

class BoostCacheFile in Boost 8

BoostCacheFile class.

Hierarchy

Expanded class hierarchy of BoostCacheFile

1 file declares its use of BoostCacheFile
BoostCacheHandler.php in src/BoostCacheHandler.php
Contains Drupal\boost\BoostCacheHandler.

File

src/BoostCacheFile.php, line 17
Contains Drupal\boost\BoostCacheFile

Namespace

Drupal\boost
View source
class BoostCacheFile {

  /**
   * Default mode for new directories.
   */
  const CHMOD_DIRECTORY = 0775;

  /**
   * The file uri.
   */
  protected $uri;

  /**
   * @var \Drupal\Core\File\FileSystem
   */
  protected $filesystem;

  /**
   * @param \Drupal\Core\File\FileSystem $filesystem
   *    Provides helpers to operate on files and stream wrappers.
   */
  public function __construct(FileSystem $filesystem) {
    $this->filesystem = $filesystem;
  }

  /**
   * Load file contents by uri.
   * @param $uri string
   */
  public function load($uri) {
    return file_get_contents($uri);
  }

  /**
   * Create new cache file.
   * @param string $uri
   * @param string $content
   */
  public function save($uri, $content) {
    $this
      ->directory($uri);
    $this
      ->modify($uri, $content);
  }

  /**
   * Delete cache file by uri.
   * @param string $uri
   */
  public function delete($uri) {
    return $this->filesystem
      ->unlink($uri);
  }

  /**
   * Make directory.
   * @param string $uri
   */
  private function directory($uri) {
    $dir = $this->filesystem
      ->dirname($uri);
    if (!file_exists($dir)) {
      $this->filesystem
        ->mkdir($dir, static::CHMOD_DIRECTORY, TRUE);
    }
  }

  /**
   * Overrite existing cache file.
   * @param string $uri
   * @param string $content
   */
  private function modify($uri, $content) {
    return file_unmanaged_save_data($content, $uri, FILE_EXISTS_REPLACE);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BoostCacheFile::$filesystem protected property
BoostCacheFile::$uri protected property The file uri.
BoostCacheFile::CHMOD_DIRECTORY constant Default mode for new directories.
BoostCacheFile::delete public function Delete cache file by uri.
BoostCacheFile::directory private function Make directory.
BoostCacheFile::load public function Load file contents by uri.
BoostCacheFile::modify private function Overrite existing cache file.
BoostCacheFile::save public function Create new cache file.
BoostCacheFile::__construct public function