You are here

class hackedFileGroup in Hacked! 6.2

Same name and namespace in other branches
  1. 7.2 includes/hackedFileGroup.inc \hackedFileGroup

Represents a group of files on the local filesystem.

Hierarchy

Expanded class hierarchy of hackedFileGroup

File

includes/hacked_project.inc, line 601

View source
class hackedFileGroup {
  var $base_path = '';
  var $files = array();
  var $files_hashes = array();
  var $file_mtimes = array();
  var $hasher;

  /**
   * Constructor.
   */
  function hackedFileGroup($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::hackedFileGroup function Constructor.
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.