You are here

class hackedFileGroup in Hacked! 8.2

Represents a group of files on the local filesystem.

Hierarchy

Expanded class hierarchy of hackedFileGroup

File

src/hackedFileGroup.php, line 10

Namespace

Drupal\hacked
View source
class hackedFileGroup {
  use StringTranslationTrait;
  var $base_path = '';
  var $files = array();
  var $files_hashes = array();
  var $file_mtimes = array();
  var $hasher;

  /**
   * Constructor.
   */
  function __construct($base_path) {
    $this->base_path = $base_path;
    $this->hasher = hacked_get_file_hasher();
  }

  /**
   * Return a new hackedFileGroup listing all files inside the given $path.
   */
  static function fromDirectory($path) {
    $filegroup = new hackedFileGroup($path);

    // Find all the files in the path, and add them to the file group.
    $filegroup
      ->scan_base_path();
    return $filegroup;
  }

  /**
   * Return a new hackedFileGroup listing all files specified.
   */
  static function fromList($path, $files) {
    $filegroup = new hackedFileGroup($path);

    // Find all the files in the path, and add them to the file group.
    $filegroup->files = $files;
    return $filegroup;
  }

  /**
   * Locate all sensible files at the base path of the file group.
   */
  function scan_base_path() {
    $files = hacked_file_scan_directory($this->base_path, '/.*/', array(
      '.',
      '..',
      'CVS',
      '.svn',
      '.git',
    ));
    foreach ($files as $file) {
      $filename = str_replace($this->base_path . '/', '', $file->filename);
      $this->files[] = $filename;
    }
  }

  /**
   * Hash all files listed in the file group.
   */
  function compute_hashes() {
    foreach ($this->files as $filename) {
      $this->files_hashes[$filename] = $this->hasher
        ->hash($this->base_path . '/' . $filename);
    }
  }

  /**
   * Determine if the given file is readable.
   */
  function is_readable($file) {
    return is_readable($this->base_path . '/' . $file);
  }

  /**
   * Determine if a file exists.
   */
  function file_exists($file) {
    return file_exists($this->base_path . '/' . $file);
  }

  /**
   * Determine if the given file is binary.
   */
  function is_not_binary($file) {
    return is_readable($this->base_path . '/' . $file) && !hacked_file_is_binary($this->base_path . '/' . $file);
  }
  function file_get_location($file) {
    return $this->base_path . '/' . $file;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
hackedFileGroup::$base_path property
hackedFileGroup::$files property
hackedFileGroup::$files_hashes property
hackedFileGroup::$file_mtimes property
hackedFileGroup::$hasher property
hackedFileGroup::compute_hashes function Hash all files listed in the file group.
hackedFileGroup::file_exists function Determine if a file exists.
hackedFileGroup::file_get_location function
hackedFileGroup::fromDirectory static function Return a new hackedFileGroup listing all files inside the given $path.
hackedFileGroup::fromList static function Return a new hackedFileGroup listing all files specified.
hackedFileGroup::is_not_binary function Determine if the given file is binary.
hackedFileGroup::is_readable function Determine if the given file is readable.
hackedFileGroup::scan_base_path function Locate all sensible files at the base path of the file group.
hackedFileGroup::__construct function Constructor.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.