You are here

function DrupalExtensionUnderscoreFinderPlugin::findFile in X Autoload 7.5

Same name and namespace in other branches
  1. 7.4 lib/ClassFinder/Plugin/DrupalExtensionUnderscoreFinderPlugin.php \Drupal\xautoload\ClassFinder\Plugin\DrupalExtensionUnderscoreFinderPlugin::findFile()

Looks up a class starting with "Drupal\$extension_name\\".

This plugin method will be called for every class beginning with "Drupal\\$extension_name\\", as long as the plugin is registered for $logical_base_path = 'Drupal/$extension_name/'.

A similar plugin will is registered along with this one for the PEAR-FLAT pattern, called for every class beginning with $modulename . '_'.

The plugin will eventually unregister itself and its cousin, once it has

  • determined the correct path for the module, and
  • determined that the module is using either PSR-0 or PSR-4. It does that by including the file candidate for PSR-0 and/or PSR-4 and checking whether the class is now defined.

The plugin will instead register a direct

Parameters

\Drupal\xautoload\ClassFinder\InjectedApi\InjectedApiInterface $api: An object with methods like suggestFile() and guessFile().

string $logical_base_path: The logical base path determined from the registered namespace. E.g. 'Drupal/menupoly/'.

string $relative_path: Remaining part of the logical path following $logical_base_path. E.g. 'FooNamespace/BarClass.php'.

string|null $extension_name: Second key that the plugin was registered with. Usually this would be the physical base directory where we prepend the relative path to get the file path. But in this case it is simply the extensions name. E.g. 'menupoly'.

Return value

bool|null TRUE, if the file was found. FALSE or NULL, otherwise.

Overrides DrupalExtensionNamespaceFinderPlugin::findFile

File

src/ClassFinder/Plugin/DrupalExtensionUnderscoreFinderPlugin.php, line 10

Class

DrupalExtensionUnderscoreFinderPlugin

Namespace

Drupal\xautoload\ClassFinder\Plugin

Code

function findFile($api, $logical_base_path, $relative_path, $extension_name = NULL) {
  $extension_file = $this->system
    ->drupalGetFilename($this->type, $extension_name);
  if (empty($extension_file)) {

    // Extension does not exist, or is not installed.
    return FALSE;
  }
  $nspath = 'Drupal/' . $extension_name . '/';
  $testpath = $nspath . 'Tests/';
  $uspath = $extension_name . '/';
  $lib = dirname($extension_file) . '/lib/';
  $lib_psr0 = $lib . 'Drupal/' . $extension_name . '/';

  // Try PEAR-Flat.
  if ($api
    ->guessPath($lib . $relative_path)) {

    // Register PEAR-Flat.
    $this->prefixMap
      ->registerDeepPath($uspath, $lib, $this->defaultBehavior);

    // Unregister the lazy plugins.
    $this->namespaceMap
      ->unregisterDeepPath($nspath, $extension_name);
    $this->prefixMap
      ->unregisterDeepPath($uspath, $extension_name);

    // See if there are PSR-0 or PSR-4 test classes.
    if (is_dir($lib_psr0 . 'Tests/')) {
      $this->namespaceMap
        ->registerDeepPath($testpath, $lib_psr0 . 'Tests/', $this->psr0Behavior);
    }
    if (is_dir($lib . 'Tests/')) {
      $this->namespaceMap
        ->registerDeepPath($testpath, $lib . 'Tests/', $this->defaultBehavior);
    }

    // The class was found, so return TRUE.
    return TRUE;
  }

  // The class was not found, so return FALSE.
  return FALSE;
}