You are here

class xautoload_Plugin_DrupalExtensionLibPrefixDeep in X Autoload 7.2

Hierarchy

Expanded class hierarchy of xautoload_Plugin_DrupalExtensionLibPrefixDeep

File

lib/Plugin/DrupalExtensionLibPrefixDeep.php, line 4

View source
class xautoload_Plugin_DrupalExtensionLibPrefixDeep extends xautoload_Plugin_WithKillswitch {
  protected $system;

  /**
   * @param xautoload_DrupalExtensionSystem $system
   *   Abstraction of Drupal's extension system.
   */
  function __construct($system) {
    $this->system = $system;
  }

  /**
   * The way this plugin is registered, it will only ever be called if the
   * class is not within a namespace. This means, all the DIRECTORY_SEPARATOR in
   * the $path parameter were underscores before.
   *
   * @param xautoload_InjectedAPI_findFile $api
   *   API object with suggestFile() method.
   * @param string $empty_string
   *   The way we register this plugin, this parameter will always be empty
   *   string.
   * @param string $path
   *   The class name converted into a path by usual PEAR rules. All underscores
   *   of the class name are replaced by DIRECTORY_SEPARATOR
   *
   * @return boolean
   *   TRUE, if we found it.
   */
  function findFile($api, $empty_string, $path) {

    // Find the first occurance of "/X", where X can be any uppercase letter.
    // We could do that with regex, but that's too expensive.
    $pos = 0;
    while (TRUE) {
      $pos = strpos($path, DIRECTORY_SEPARATOR);
      if (FALSE === $pos) {

        // There is no place like DIRECTORY_SEPARATOR + uppercase character in
        // the path. Thus, this is not a class we are interested in.
        return FALSE;
      }

      // Pick the character following the DIRECTORY_SEPARATOR.
      $char = @$path[$pos + 1];
      if (isset($char) && 'A' <= $char && $char <= 'Z') {

        // We found a '_' followed by an uppercase character.
        break;
      }

      // We hit a normal DIRECTORY_SEPARATOR followed by a lowercase character.
      // We assume this previously was a '_' in the module name.
      $path[$pos] = '_';
    }
    if (FALSE !== $pos) {

      // We found a position, so let's work with that.
      $extension = substr($path, 0, $pos);
      $extension_path = $this->system
        ->getExtensionPath($extension);
      if (!empty($extension_path)) {
        $path = $extension_path . '/lib/' . substr($path, $pos + 1);
        if ($api
          ->suggestFile($path)) {
          return TRUE;
        }
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
xautoload_Plugin_DrupalExtensionLibPrefixDeep::$system protected property
xautoload_Plugin_DrupalExtensionLibPrefixDeep::findFile function The way this plugin is registered, it will only ever be called if the class is not within a namespace. This means, all the DIRECTORY_SEPARATOR in the $path parameter were underscores before. Overrides xautoload_Plugin_Interface::findFile
xautoload_Plugin_DrupalExtensionLibPrefixDeep::__construct function
xautoload_Plugin_WithKillswitch::$id protected property
xautoload_Plugin_WithKillswitch::$key protected property
xautoload_Plugin_WithKillswitch::$map protected property
xautoload_Plugin_WithKillswitch::setKillswitch function Allow the namespace plugin to unsubscribe or replace itself. This is called by the ClassFinder itself, the moment the namespace plugin is registered.