function VirtualFilesystem::getFileContents in X Autoload 7.4
Same name and namespace in other branches
- 7.5 tests/src/Filesystem/VirtualFilesystem.php \Drupal\xautoload\Tests\Filesystem\VirtualFilesystem::getFileContents()
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 VirtualFilesystem::getFileContents()
- VirtualFilesystem::getStat in tests/
lib/ Filesystem/ VirtualFilesystem.php
File
- tests/
lib/ Filesystem/ VirtualFilesystem.php, line 195
Class
Namespace
Drupal\xautoload\Tests\FilesystemCode
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.");
}
$instance_key_export = var_export($this->instanceKey, TRUE);
$path_export = var_export($path, TRUE);
if (self::FILE === $this->knownPaths[$path]) {
// Empty PHP file..
return <<<EOT
<?php
Drupal\\xautoload\\Tests\\Filesystem\\VirtualFilesystem::reportFileIncluded({<span class="php-variable">$instance_key_export</span>}, {<span class="php-variable">$path_export</span>});
EOT;
}
// PHP file with class definition.
$class = $this->knownPaths[$path];
if (FALSE === ($pos = strrpos($class, '\\'))) {
// Class without namespace.
return <<<EOT
<?php
Drupal\\xautoload\\Tests\\Filesystem\\VirtualFilesystem::reportFileIncluded({<span class="php-variable">$instance_key_export</span>}, {<span class="php-variable">$path_export</span>});
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>};
\\Drupal\\xautoload\\Tests\\Filesystem\\VirtualFilesystem::reportFileIncluded({<span class="php-variable">$instance_key_export</span>}, {<span class="php-variable">$path_export</span>});
class {<span class="php-variable">$classname</span>} {}
EOT;
}