How to use Pear Libraries inside plugins

Back to Plugin Development index

This is a proposal for a standard way to include Pear libraries in plugins, so the structure can be shared by other plugins.

  • Create a “pear” (all small caps) directory inside the “plugins” directory.
  • Put the Pear package(s) inside the “pear” folder, following the Pear structure.
  • Add the following code to the very beginning of the plugin file (this will add the plugins/pear directory to PHP's include path, so the Pear classes will be found anywhere):
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . $DIR_PLUGINS . 'pear');
  • Require the library inside methods using require_once, right before the Pear class is called. Example:
...
require_once 'Pager/Pager.php';
$pager = Pager::factory($this->pager_options);
...
plugindev/pear.txt · Last modified: 2006/07/05 13:03 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki