You are here

function DummyFilesystem::getFileContents in X Autoload 7.3

Parameters

$path: The file path.

Return value

string The file contents.

Throws

\Exception Exception thrown if there is no file at $path.

1 call to DummyFilesystem::getFileContents()
DummyFilesystem::getStat in tests/Drupal/xautoload/Tests/DummyFilesystem.php

File

tests/Drupal/xautoload/Tests/DummyFilesystem.php, line 112

Class

DummyFilesystem

Namespace

Drupal\xautoload\Tests

Code

function getFileContents($path) {
  if (!isset($this->knownPaths[$path])) {

    // File does not exist.
    throw new \Exception("Assumed file '{$path}' does not exist.");
  }
  elseif (self::DIR === $this->knownPaths[$path]) {
    throw new \Exception("Assumed file '{$path}' is a directory.");
  }
  if (self::FILE === $this->knownPaths[$path]) {

    // Empty PHP file..
    return '<?php';
  }

  // PHP file with class definition.
  $class = $this->knownPaths[$path];
  if (FALSE === ($pos = strrpos($class, '\\'))) {

    // Class without namespace.
    return <<<EOT
<?php
class {<span class="php-variable">$class</span>} {}
EOT;
  }

  // Class without namespace.
  $namespace = substr($class, 0, $pos);
  $classname = substr($class, $pos + 1);
  return <<<EOT
<?php
namespace {<span class="php-variable">$namespace</span>};
class {<span class="php-variable">$classname</span>} {}
EOT;
}