[drupal-devel] question about external php module dependencies
Nedjo Rogers
nedjo at gworks.ca
Wed Apr 20 20:47:18 UTC 2005
How to use PEAR in a contributed module is a question I've been looking
at as well.
> We try not to require any external code for Drupal, especially since
> many hosts might
> not have PEAR available.
It's easy enough to use PEAR packages without a PEAR install, but it
requires manual configuration (i.e., extraction of packages into correct
directory structure) something that goes beyond what should be expected
for module installation...
> ... you aren't
> allowed to include non-GPL code with your module.
and few packages are GPL (the ones you cite being PHP and BSD,
respectively).
So, perhaps, the best approach is to provide a preconfigured PEAR
directory as a separate download (e.g., on your server/website, linked
in the module install text).
Here's a quick idea of a module to facilitate PEAR use. I've put in
help text, but it's really for module authors rather than users. You'll
see it does nothing but set the include path! But I suppose it could
also use directory uploading to put the needed PEAR files in place.
<?php
// $Id:
/**
* @file
* Facilitates the use of PEAR packages in Drupal.
*/
// Add the PEAR/ directory to your include path.
$path = $_SERVER['PATH_TRANSLATED'];
$dir = substr($path, 0, strrpos($path, '/modules/') + 1);
ini_set('include_path', $dir . 'PEAR/' . PATH_SEPARATOR .
ini_get('include_path'));
/**
* Implementation of hook_help().
*/
function pear_help($section) {
switch ($section) {
case 'admin/help#pear':
$output = t("
<h3>Using PEAR</h3>
<p>The PEAR module is designed to facilitate use of PEAR packages
within Drupal in cases where the package are not available on the host
server. In this case (since most PEAR packages are not GPl and
therefore can't be included within Drupal.org module downloads), it's
necessary to post packages for separate download and install. To use
the module:
<ul>
<li>Install your desired PEAR package(s), and all of their
dependencies, in a directory called PEAR. For example, for the packages
HTTP_Request and XML_Serializer, the install might include:
<pre>PEAR
-HTTP
-Request.php
-Request
-...
-XML
-Serializer.php
-Serializer
-...</pre>
</li>
<li>Create a tar.gz file of the PEAR directory and it contents,
and post it for download (e.g., on your website/server).</li>
<li>Instruct your users to download and uncompress the tar.gz
file into their base Drupal directory.</li>
<li>Enable the PEAR module.</li>
</ul>
");
return $output;
case 'admin/modules#description':
return t('Facilitates the use of PEAR packages in Drupal.');
}
}
?>
________
Nedjo Rogers
Learning Technologies Developer
GroundWorks Learning Centre
(250) 360-0799
nedjo at gworks.ca
More information about the drupal-devel
mailing list