You are here

public function AutoloadCache::__construct in Autoload 7.2

Parameters

string $file: A path to file for storing the autoloading map.

Overrides ArrayContainer::__construct

File

./autoload.cache.inc, line 128
Autoload cache controller.

Class

AutoloadCache
Class AutoloadCache.

Code

public function __construct($file) {
  parent::__construct();
  $this->file = $file;
  $this->binExists = db_table_exists(static::BIN);
  if (is_readable($this->file)) {
    $this->data = (require $this->file);
  }

  // If the file doesn't exist, not readable or doesn't contain a map.
  if (empty($this->data) || !is_array($this->data)) {
    $this->data = $this->binExists ? db_select(static::BIN)
      ->fields(static::BIN)
      ->execute()
      ->fetchAllAssoc('namespace', \PDO::FETCH_ASSOC) : array();

    // Rebuild if a database is empty, try to store data in file otherwise.
    empty($this->data) ? $this
      ->rebuild() : $this
      ->updateFile();
  }
}