0

I'm using libraries, not using composer, and it's on Drupal 7. I installed and enabled xautoload so that I can use classes from a library that has namespacing. I think I got the xautoload function of this working correctly, because it is not throwing errors anymore when I have a use SSRS\SSRSReport; statement at the top of my module file referencing the library's classes.

The problem is that I still seem to have some namespacing fatal error in a libary's class file. This is my hook_libraries_info():

/**
 * Implements hook_libraries_info().
 *
 * For defining external libraries.
 */
function ssrs_libraries_info() {
  $libraries['ssrs-sdk'] = array(
    'name' => 'SSRS SDK for PHP',
    'vendor url' => 'https://github.com/EmergencyReporting/ssrsreport',
    'download url' => 'https://github.com/EmergencyReporting/ssrsreport',
    'version callback' => 'ssrs_get_version',
    'files' => array(
      'php' => array('library/SSRS/SSRSReport.php'),
    ),
    'xautoload' => function($adapter) {
      // Register a namespace with PSR-0 root in <library dir>/library/
      // Note: $adapter already knows the <library dir>.
      $adapter->add('SSRS', 'library');
    },
  );
  return $libraries;
}

Anyways, the error I get is this:

Fatal error: Interface 'SSRS\Interfaces\ISSRSBaseType' not found in /sites/all/libraries/ssrs-sdk/library/SSRS/SSRSType/ExecutionInfo2.php on line 34

And the line the error in ExecutionInfo2.php is on the line starting class ExecutionInfo2 ...:

namespace SSRS\SSRSType;
use SSRS\Interfaces\ISSRSBaseType;

/**
 *
 * class ExecutionInfo2
 */
class ExecutionInfo2 extends SSRSBaseType implements ISSRSBaseType {

So I don't get errors from the namespaces' use statements, but the interface class doesn't appear to actually be loaded yet.

1

I found out that despite not using composer, I can give the library's provided composer.json file to xautoload, and it will get the information it needs.

$adapter->composerJson('composer.json');

I also found in the composer.json file the information I would have needed to use $adapter->addPsr4, with each individual namespace needing to be added separately:

"autoload": {
    "psr-4": {
        "SSRS\\": "library/SSRS/",
        "SSRS\\Common\\": "library/SSRS/Common/",
        "SSRS\\Factory\\": "library/SSRS/Factory/",
        "SSRS\\Interfaces\\": "library/SSRS/Interface/",
        "SSRS\\RenderType\\": "library/SSRS/RenderType/",
        "SSRS\\SSRSType\\": "library/SSRS/SSRSType/",
        "SSRS\\TestConnection\\": "library/SSRS/TestConnection/"
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.