Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
In order to use PEAR modules, they must be on the PHP include_path. Is there some way that libraries can support this?
Comments
Comment #1
pillarsdotnet CreditAttribution: pillarsdotnet commentedFor instance, I wrote the Mail MIME module as a Drupal-friendly wrapper around the PEAR Mail_mime module.
My first inclination was to use Libraries API to track whether Mail_mime is installed. I wrote a hook_requirements() function to perform this check.
Then I realized that Libraries won't detect PEAR modules 'cuz they aren't installed in a Libraries directory. Tried using hook_library() to specify the places where it should look, but realized that I can't because they might be in any location on the include path.
Then I found out that PEAR libraries require_once() each other willy-nilly, so it's a lost cause. Libraries API just doesn't support the include path, nor the concept that required library files may be installed somewhere outside the Drupal site, nor the concept that some library files must be on the include path in order for them to work correctly.
Looked for another project that supports PEAR in D7 and struck out. There are two for D6 but neither one has a D7 version in the works.
Wound up punting by creating a file_default_scheme()://PEAR directory and adding it to the include path with a hook_init() implementation.
If there were some way to accomplish the same task using Libraries API, I'd be willing, even if it makes my code bigger.
Comment #2
tstoecklerSorry, if I'm being stupid, but I don't quite get what the problem is you are having.
Could you give an example of where you would want your library to be located?
Libraries API (7.x-2.x) has the notion of 'libraries path' which you could specify if it can't be one of the libraries folders. But it seems that the exact location doesn't really matter? Again, I don't quite get it yet.
Comment #3
sunPEAR libraries are usually installed through the OS package manager, and usually reside somewhere in /usr/share/php or similar.
PHP accesses those libraries through a customized php.ini include_path. Performance-wise, not really the best way to load/include files... but yeah, that's how PEAR libraries are supposed to work.
file_exists() on those include file paths can throw errors or warnings, because the files are outside of the webspace.
I don't really have an idea for this issue yet. I can only guess that the solution will require a custom library detection callback (which literally simply tries a class_exists() or similar to invoke PHP's auto-loading and includes those libraries at runtime [or not])
Comment #4
pillarsdotnet CreditAttribution: pillarsdotnet commentedWell, for now I'm using
@fopen($path, TRUE)
to detect whether files exist. Thehook_requirements()
implementation returns aREQUIREMENT_WARNING
on failure to auto-create a directory andREQUIREMENT_ERROR
on failure to download, install, or read a file.Comment #5
ohnobinki CreditAttribution: ohnobinki commented+1
The ideal and cleanest way to manage external libraries is to let them be installed by the package manager into something external from Drupal.
This goes for more than just PEAR modules.
Comment #6
pocock CreditAttribution: pocock commentedThe README.Debian for the new Libraries API package on Debian provides some clues about this:
http://danielpocock.com/drupal-on-debian-libraries-api