protected function xautoload_Plugin_DrupalSimpletest::getExtensionPath in X Autoload 7.2
Helper function to get the path for an extension.
1 call to xautoload_Plugin_DrupalSimpletest::getExtensionPath()
- xautoload_Plugin_DrupalSimpletest::findFile in lib/
Plugin/ DrupalSimpletest.php - Expect a class Drupal\(module)\Tests\SomeTest to be in (module dir)/lib/Drupal/(module)/Tests/SomeTest.php, but consider the PHP include_path setting.
File
- lib/
Plugin/ DrupalSimpletest.php, line 41
Class
Code
protected function getExtensionPath($extension) {
// Ok, this is a lot of nested if().
// But trust me, that's the most performant way to cut it.
// Do we already have this extension's path in cache?
if (!isset($this->extensions[$extension])) {
// .. Nope.
// But we might have the path to the .module or .info file, and only need
// to get the dirname() of that.
if (!isset($this->extensionsRaw[$extension])) {
// Ok we don't even have that. Are we even initialized?
if (isset($this->extensionsRaw)) {
// Yes, we are already initialized.
// So apparently the extension doesn't exist.
return;
}
else {
// Initialize the extensionsRaw.
// The filename can be e.g.
// (module path)/(module name).module, OR
// (theme path)/(theme name).info
$this->extensionsRaw = db_query("SELECT name, filename FROM {system}")
->fetchAllKeyed();
// We could now continue to process all of those to get the dirname(),
// but we prefer it the lazy way.
// Now it could be that we suddenly have our extension.
if (!isset($this->extensionsRaw[$extension])) {
// Nope, still don't have it.
return;
}
}
}
// Ok, now we know the extension is in $this->extensionsRaw, but not in
// $this->extensions.
$this->extensions[$extension] = dirname($this->extensionsRaw[$extension]) . '/lib/Drupal/';
}
// Now we know that we have the ../lib/Drupal/ path for this extension.
return $this->extensions[$extension];
}